3fdb276
Remove unnecessary 1ms wakeups while USB transfers are in progress
3fdb276
3fdb276
--- linux.c.orig	2007-12-02 16:02:27.000000000 -0800
3fdb276
+++ linux.c	2007-12-02 16:33:12.000000000 -0800
3fdb276
@@ -14,6 +14,7 @@
3fdb276
 #include <errno.h>
3fdb276
 #include <sys/time.h>
3fdb276
 #include <dirent.h>
3fdb276
+#include <poll.h>
3fdb276
 
3fdb276
 #include "linux.h"
3fdb276
 #include "usbi.h"
3fdb276
@@ -164,7 +165,7 @@
3fdb276
 {
3fdb276
   struct usb_urb urb;
3fdb276
   int bytesdone = 0, requested;
3fdb276
-  struct timeval tv, tv_ref, tv_now;
3fdb276
+  struct timeval tv_ref, tv_now;
3fdb276
   struct usb_urb *context;
3fdb276
   int ret, waiting;
3fdb276
 
3fdb276
@@ -191,8 +192,6 @@
3fdb276
   }
3fdb276
 
3fdb276
   do {
3fdb276
-    fd_set writefds;
3fdb276
-
3fdb276
     requested = size - bytesdone;
3fdb276
     if (requested > MAX_READ_WRITE)
3fdb276
       requested = MAX_READ_WRITE;
3fdb276
@@ -213,25 +212,25 @@
3fdb276
       return ret;
3fdb276
     }
3fdb276
 
3fdb276
-    FD_ZERO(&writefds);
3fdb276
-    FD_SET(dev->fd, &writefds);
3fdb276
-
3fdb276
 restart:
3fdb276
     waiting = 1;
3fdb276
     context = NULL;
3fdb276
     while (!urb.usercontext && ((ret = ioctl(dev->fd, IOCTL_USB_REAPURBNDELAY, &context)) == -1) && waiting) {
3fdb276
-      tv.tv_sec = 0;
3fdb276
-      tv.tv_usec = 1000; // 1 msec
3fdb276
-      select(dev->fd + 1, NULL, &writefds, NULL, &tv;; //sub second wait
3fdb276
+      struct pollfd pollfd;
3fdb276
+      int poll_timeout = -1;
3fdb276
+
3fdb276
+      pollfd.fd = dev->fd;
3fdb276
+      pollfd.events = POLLOUT;
3fdb276
+      pollfd.revents = 0;
3fdb276
 
3fdb276
       if (timeout) {
3fdb276
-        /* compare with actual time, as the select timeout is not that precise */
3fdb276
         gettimeofday(&tv_now, NULL);
3fdb276
-
3fdb276
-        if ((tv_now.tv_sec > tv_ref.tv_sec) ||
3fdb276
-            ((tv_now.tv_sec == tv_ref.tv_sec) && (tv_now.tv_usec >= tv_ref.tv_usec)))
3fdb276
-          waiting = 0;
3fdb276
+        poll_timeout = (tv_ref.tv_sec-tv_now.tv_sec)*1000 +
3fdb276
+                       (tv_ref.tv_usec-tv_now.tv_usec)/1000;
3fdb276
       }
3fdb276
+
3fdb276
+      if ((ret = poll(&pollfd, 1, poll_timeout)) != 1)
3fdb276
+        waiting = 0;
3fdb276
     }
3fdb276
 
3fdb276
     if (context && context != &urb) {