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
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
+#include <poll.h>
#include <stdlib.h>
#include <sys/types.h>
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;
+}
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 */