diff options
| author | Ray Strode <rstrode@redhat.com> | 2007-05-16 15:50:31 -0400 |
|---|---|---|
| committer | Ray Strode <rstrode@redhat.com> | 2007-05-16 15:50:31 -0400 |
| commit | e7c3b04e4f9293d01f494bafb84243b02abb22ad (patch) | |
| tree | 32198054b25eb4c1076e43205e5120fdf5017a79 /src | |
| parent | 088020c3c2711bb2378e263636e117cfa3855eb3 (diff) | |
add ply_fd_has_data and ply_fd_can_take_data apis
The calls in this commit just do a one-off poll of the passed
in fd to see if the fd is read for read or write call
Diffstat (limited to 'src')
| -rw-r--r-- | src/ply-utils.c | 29 | ||||
| -rw-r--r-- | src/ply-utils.h | 2 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/ply-utils.c b/src/ply-utils.c index 5db4a7f..b793c61 100644 --- a/src/ply-utils.c +++ b/src/ply-utils.c @@ -5,6 +5,7 @@ #include <assert.h> #include <errno.h> #include <fcntl.h> +#include <poll.h> #include <stdlib.h> #include <sys/types.h> @@ -70,3 +71,31 @@ ply_write (int fd, return bytes_left_to_write == 0; } + +bool +ply_fd_has_data (int fd) +{ + struct pollfd poll_data; + int result; + + poll_data.fd = fd; + poll_data.events = POLLIN | POLLPRI; + poll_data.revents = 0; + result = poll (&poll_data, 1, 10); + + return result == 1; +} + +bool +ply_fd_can_take_data (int fd) +{ + struct pollfd poll_data; + int result; + + poll_data.fd = fd; + poll_data.events = POLLOUT; + poll_data.revents = 0; + result = poll (&poll_data, 1, 10); + + return result == 1; +} diff --git a/src/ply-utils.h b/src/ply-utils.h index 8b2ceee..32bf618 100644 --- a/src/ply-utils.h +++ b/src/ply-utils.h @@ -44,6 +44,8 @@ bool ply_open_unidirectional_pipe (int *sender_fd, bool ply_write (int fd, const void *buffer, size_t number_of_bytes); +bool ply_fd_has_data (int fd); +bool ply_fd_can_take_data (int fd); #endif #endif /* PLY_UTILS_H */ |
