summaryrefslogtreecommitdiffstats
path: root/include/libtf/io.h
blob: 87a6c90e363a37683d494b982df6494fca39d98f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* tf.h - libtf io header
 *
 * Copyright (C) 2009 Timo Teräs <timo.teras@iki.fi>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 or later as
 * published by the Free Software Foundation.
 *
 * See http://www.gnu.org/ for details.
 */

#ifndef TF_IO_H
#define TF_IO_H

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/in.h>

#include <libtf/defines.h>

struct tf_fiber;

struct tf_sockaddr {
	union {
		struct sockaddr		addr;
		struct sockaddr_in	in;
		struct sockaddr_in6	in6;
	};
};

struct tf_fd {
	int fd;
	unsigned int flags;
	/* Single waiter -- would be relatively trivial to modify to allow
	 * multiple waiters, if someone actually needs it */
	unsigned int events;
	struct tf_fiber *waiting_fiber;
};

void tf_poll_init(void);
int  tf_poll(tf_mtime_diff_t timeout);
void tf_poll_close(void);

int tf_open(struct tf_fd *fd, const char *pathname, int flags);
int tf_open_fd(struct tf_fd *fd, int kfd);
int tf_close(struct tf_fd *fd);
int tf_read(struct tf_fd *fd, void *buf, size_t count, int timeout);
int tf_write(struct tf_fd *fd, const void *buf, size_t count, int timeout);

int tf_socket(struct tf_fd *fd, int domain, int type, int protocol);
int tf_bind(struct tf_fd *fd, const struct tf_sockaddr *addr);
int tf_listen(struct tf_fd *fd, int backlog);
int tf_accept(struct tf_fd *fd);
int tf_connect(struct tf_fd *fd, const struct tf_sockaddr *addr, int timeout);

ssize_t tf_recv(struct tf_fd *fd, void *buf, size_t count, int timeout);
ssize_t tf_send(struct tf_fd *fd, const void *buf, size_t count, int timeout);
ssize_t tf_recvmsg(struct tf_fd *fd,
		   struct tf_sockaddr *from, struct tf_sockaddr *to,
		   void *buf, size_t count, int timeout);
ssize_t tf_sendmsg(struct tf_fd *fd,
		   struct tf_sockaddr *from, const struct tf_sockaddr *to,
		   const void *buf, size_t count, int timeout);

int tf_query_dns(const char *name, int num_res, struct tf_sockaddr *res,
		 int timeout);

#endif