From 2b19cc385163a43b1d559074a795a8aaab751185 Mon Sep 17 00:00:00 2001 From: Timo Teras Date: Wed, 25 Nov 2009 15:11:20 +0200 Subject: libtf: implement basic networking i/o pretty much untested. also some slight changes to how scheduler is invoked. --- include/libtf/defines.h | 2 -- include/libtf/fiber.h | 15 +++++++++++---- include/libtf/io.h | 28 +++++++++++++++++----------- 3 files changed, 28 insertions(+), 17 deletions(-) (limited to 'include/libtf') diff --git a/include/libtf/defines.h b/include/libtf/defines.h index 144ad63..ae72980 100644 --- a/include/libtf/defines.h +++ b/include/libtf/defines.h @@ -72,8 +72,6 @@ #endif /* Monotonic time */ -#define TF_INFINITE -1 - typedef uint32_t tf_mtime_t; typedef int32_t tf_mtime_diff_t; diff --git a/include/libtf/fiber.h b/include/libtf/fiber.h index 91c0b3b..36c2812 100644 --- a/include/libtf/fiber.h +++ b/include/libtf/fiber.h @@ -28,6 +28,10 @@ #define TF_WAKEUP_TIMEOUT ETIMEDOUT #define TF_WAKEUP_FD EIO +/* Special timeouts for tf_schedule() */ +#define TF_NO_TIMEOUT -1 +#define TF_NO_TIMEOUT_CHANGE -2 + /* Scheduler */ struct tf_fiber; @@ -77,11 +81,14 @@ void tf_fiber_put(void *data); void tf_exit(void) attribute_noreturn; void tf_kill(void *fiber); -int tf_schedule(int wakeup_type); -int tf_schedule_timeout(int milliseconds); +int tf_schedule(int milliseconds); void tf_wakeup(struct tf_fiber *fiber, int wakeup_type); - int tf_yield(void); -int tf_msleep(int milliseconds); + +static inline +int tf_msleep(int milliseconds) +{ + return tf_schedule(milliseconds); +} #endif diff --git a/include/libtf/io.h b/include/libtf/io.h index 87a6c90..8f5b54d 100644 --- a/include/libtf/io.h +++ b/include/libtf/io.h @@ -20,6 +20,12 @@ #include +/* Flags for tf_open_fd() */ +#define TF_FD_AUTOCLOSE 1 +#define TF_FD_STREAM_ORIENTED 2 +#define TF_FD_SET_CLOEXEC 4 +#define TF_FD_ALREADY_NONBLOCKING 8 + struct tf_fiber; struct tf_sockaddr { @@ -27,7 +33,7 @@ struct tf_sockaddr { struct sockaddr addr; struct sockaddr_in in; struct sockaddr_in6 in6; - }; + } u; }; struct tf_fd { @@ -43,28 +49,28 @@ void tf_poll_init(void); int tf_poll(tf_mtime_diff_t timeout); void tf_poll_close(void); +int tf_open_fd(struct tf_fd *fd, int kfd, int flags); 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_read(struct tf_fd *fd, void *buf, size_t count, tf_mtime_diff_t timeout); +int tf_write(struct tf_fd *fd, const void *buf, size_t count, tf_mtime_diff_t 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); +int tf_accept(struct tf_fd *listen_fd, struct tf_fd *child_fd, + struct tf_sockaddr *from, tf_mtime_diff_t timeout); +int tf_connect(struct tf_fd *fd, const struct tf_sockaddr *addr, tf_mtime_diff_t timeout); + ssize_t tf_recvmsg(struct tf_fd *fd, struct tf_sockaddr *from, struct tf_sockaddr *to, - void *buf, size_t count, int timeout); + void *buf, size_t count, tf_mtime_diff_t 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); + const void *buf, size_t count, tf_mtime_diff_t timeout); int tf_query_dns(const char *name, int num_res, struct tf_sockaddr *res, - int timeout); + tf_mtime_diff_t timeout); #endif -- cgit v1.2.3