s3: Add sys_poll_intr
authorVolker Lendecke <vl@samba.org>
Tue, 8 Feb 2011 16:28:27 +0000 (17:28 +0100)
committerVolker Lendecke <vlendec@samba.org>
Mon, 28 Feb 2011 15:40:19 +0000 (16:40 +0100)
lib/util/select.c
lib/util/select.h

index b40538c473e828a22cae33014fd4edabf9cf0126..5f1c91cff62a0acc2a00d453f76a66efef1b926e 100644 (file)
@@ -286,3 +286,29 @@ int sys_poll(struct pollfd *fds, int num_fds, int timeout)
 
        return ret;
 }
+
+int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout)
+{
+       int orig_timeout = timeout;
+       struct timespec start;
+       int ret;
+
+       clock_gettime_mono(&start);
+
+       while (true) {
+               struct timespec now;
+               int64_t elapsed;
+
+               ret = poll(fds, num_fds, timeout);
+               if (ret != -1) {
+                       break;
+               }
+               if (errno != EINTR) {
+                       break;
+               }
+               clock_gettime_mono(&now);
+               elapsed = nsec_time_diff(&now, &start);
+               timeout = (orig_timeout - elapsed) / 1000000;
+       };
+       return ret;
+}
index 795c8fa454c1e471d9958f073956e776e5977c2b..3c762de2adc19077191ac6bfe28e67e63e34e41a 100644 (file)
@@ -28,5 +28,6 @@ void sys_select_signal(char c);
 int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval);
 int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval);
 int sys_poll(struct pollfd *fds, int num_fds, int timeout);
+int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout);
 
 #endif