]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Just use a simple 250ms sleep in the read loop (Issue #72)
authorMichael R Sweet <msweet@msweet.org>
Mon, 1 Feb 2021 20:47:50 +0000 (15:47 -0500)
committerMichael R Sweet <msweet@msweet.org>
Mon, 1 Feb 2021 20:48:28 +0000 (15:48 -0500)
CHANGES-OPENPRINTING.md
backend/usb-libusb.c

index f7997716995d74157a6ed0a95189803eea5a763c..67b00b82b0a000d40af939536c224ac448658faa 100644 (file)
@@ -14,6 +14,8 @@ Changes in CUPS v2.3.3op2
 - Fixed regression in `snprintf` emulation function (Issue #67)
 - The scheduler's systemd service file now waits for the nslcd service to start
   (Issue #69)
+- The libusb-based USB backend now uses a simpler read timer implementation to
+  avoid a regression in a previous change (Issue #72)
 - Fixed segfault in help.cgi when searching in man pages (Issue #81)
 - Root certificates were incorrectly stored in "~/.cups/ssl".
 
index 393fe65eeeeae55c1958797f2570e8d60b28ffcf..d6b0eb423249732a71ff9fa83160ca98e6a1919a 100644 (file)
@@ -1690,45 +1690,24 @@ static void *read_thread(void *reference)
   unsigned char                readbuffer[512];
   int                  rbytes;
   int                  readstatus;
-  struct timeval       now,
-                       delay,
-                       end,
-                       timeleft;
 
 
   (void)reference;
 
- /*
-  * Read frequency: once every 250 milliseconds.
-  */
-
-  delay.tv_sec = 0;
-  delay.tv_usec = 250000;
-
   do
   {
    /*
-    * Remember when we started so we can throttle the loop after the read
-    * call...
-    */
-
-    gettimeofday(&now, NULL);
-
-   /*
-    * Calculate what 250 milliSeconds are in absolute time...
+    * Try reading from the OUT (to host) endpoint...
     */
 
-    timeradd(&now, &delay, &end);
-
     rbytes     = sizeof(readbuffer);
     readstatus = libusb_bulk_transfer(g.printer->handle,
                                      g.printer->read_endp,
                                      readbuffer, rbytes,
-                                     &rbytes, 60000);
+                                     &rbytes, 250);
     if (readstatus == LIBUSB_SUCCESS && rbytes > 0)
     {
-      fprintf(stderr, "DEBUG: Read %d bytes of back-channel data...\n",
-              (int)rbytes);
+      fprintf(stderr, "DEBUG: Read %d bytes of back-channel data...\n", (int)rbytes);
       cupsBackChannelWrite((const char *)readbuffer, (size_t)rbytes, 1.0);
     }
     else if (readstatus == LIBUSB_ERROR_TIMEOUT)
@@ -1743,15 +1722,9 @@ static void *read_thread(void *reference)
     */
 
     if ((g.wait_eof || !g.read_thread_stop))
-    {
-      gettimeofday(&now, NULL);
-      if (timercmp(&now, &end, <))
-      {
-       timersub(&end, &now, &timeleft);
-       usleep(1000000 * timeleft.tv_sec + timeleft.tv_usec);
-      }
-    }
-  } while (g.wait_eof || !g.read_thread_stop);
+      usleep(250000);
+  }
+  while (g.wait_eof || !g.read_thread_stop);
 
  /*
   * Let the main thread know that we have completed the read thread...