diff options
Diffstat (limited to 'include/libtf/io.h')
-rw-r--r-- | include/libtf/io.h | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/include/libtf/io.h b/include/libtf/io.h new file mode 100644 index 0000000..87a6c90 --- /dev/null +++ b/include/libtf/io.h @@ -0,0 +1,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 |