diff options
author | Timo Teras <timo.teras@iki.fi> | 2009-11-25 16:53:02 +0200 |
---|---|---|
committer | Timo Teras <timo.teras@iki.fi> | 2009-11-25 16:53:02 +0200 |
commit | 4db830052d941d9c6de281bc9a2f6ac212c59ad8 (patch) | |
tree | 3a9b5e7c78a812fc582f8844703069e5692a0c94 /src/io-unix.c | |
parent | 2b19cc385163a43b1d559074a795a8aaab751185 (diff) | |
download | libtf-4db830052d941d9c6de281bc9a2f6ac212c59ad8.tar.bz2 libtf-4db830052d941d9c6de281bc9a2f6ac212c59ad8.tar.xz |
libtf: minor changes and new test case for network i/o
fixup the internals a bit.
Diffstat (limited to 'src/io-unix.c')
-rw-r--r-- | src/io-unix.c | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/io-unix.c b/src/io-unix.c index cc1bd1b..8ed8e42 100644 --- a/src/io-unix.c +++ b/src/io-unix.c @@ -90,7 +90,8 @@ int tf_close(struct tf_fd *fd) return 0; } -int tf_read(struct tf_fd *fd, void *buf, size_t count, tf_mtime_diff_t timeout) +int tf_read_fully(struct tf_fd *fd, void *buf, size_t count, + tf_mtime_diff_t timeout) { ssize_t n; int r; @@ -127,8 +128,8 @@ int tf_read(struct tf_fd *fd, void *buf, size_t count, tf_mtime_diff_t timeout) return -r; } -int tf_write(struct tf_fd *fd, const void *buf, size_t count, - tf_mtime_diff_t timeout) +int tf_write_fully(struct tf_fd *fd, const void *buf, size_t count, + tf_mtime_diff_t timeout) { ssize_t n; int r; @@ -162,6 +163,53 @@ int tf_write(struct tf_fd *fd, const void *buf, size_t count, return -r; } +ssize_t tf_read(struct tf_fd *fd, void *buf, size_t count, tf_mtime_diff_t timeout) +{ + ssize_t n; + + tf_fd_monitor(fd, EPOLLIN); + do { + n = read(fd->fd, buf, count); + if (n >= 0) + break; + if (errno == EINTR) + continue; + if (errno != EAGAIN) { + n = -errno; + break; + } + n = tf_schedule(timeout); + timeout = TF_NO_TIMEOUT_CHANGE; + } while (n == TF_WAKEUP_FD); + tf_fd_unmonitor(fd); + + return n; +} + +ssize_t tf_write(struct tf_fd *fd, const void *buf, size_t count, + tf_mtime_diff_t timeout) +{ + ssize_t n; + + tf_fd_monitor(fd, EPOLLOUT); + do { + n = write(fd->fd, buf, count); + if (n >= 0) + break; + if (errno == EINTR) + continue; + if (errno != EAGAIN) { + n = -errno; + break; + } + n = tf_schedule(timeout); + timeout = TF_NO_TIMEOUT_CHANGE; + } while (n == TF_WAKEUP_FD); + tf_fd_unmonitor(fd); + + return n; +} + int tf_socket(struct tf_fd *fd, int domain, int type, int protocol) { int kfd, tfdf, on = 1; |