]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
add ply_fd_has_data and ply_fd_can_take_data apis
authorRay Strode <rstrode@redhat.com>
Wed, 16 May 2007 19:50:31 +0000 (15:50 -0400)
committerRay Strode <rstrode@redhat.com>
Wed, 16 May 2007 19:50:31 +0000 (15:50 -0400)
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

src/ply-utils.c
src/ply-utils.h

index 5db4a7fd0b32a5f5212bc8cea68d0828c106ff3e..b793c614f2a0291d4d9254724d5cda2991b2dd99 100644 (file)
@@ -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;
+}
index 8b2ceee3c2fd1c8de5d27e639039bd28e6d93fcf..32bf6186fe06a940470f3b7cc1ba68fa2a427db1 100644 (file)
@@ -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 */