path: root/include/libtf/io.h
diff options
authorTimo Teras <>2009-11-25 10:52:15 +0200
committerTimo Teras <>2009-11-25 10:52:15 +0200
commitfc1044daf51f32b9d85f8497e4e0bd5a3c1e7fe9 (patch)
tree52e11c88f17c47c0d086761e50b266f5c5ccd061 /include/libtf/io.h
parentcec85dedb7fd66cf2c23cafadd7c53eb7afed78f (diff)
libtf: implement basic file i/o with epoll
some scetching of i/o api, and implement basic read and write functionality. integrate polling to scheduler and an epoll based polling mechanism.
Diffstat (limited to 'include/libtf/io.h')
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 <>
+ * 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 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);