From: Michael R Sweet Date: Mon, 1 Feb 2021 20:47:50 +0000 (-0500) Subject: Just use a simple 250ms sleep in the read loop (Issue #72) X-Git-Tag: v2.3.3op2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db53b49265baf9da15d6b6f3ed9dcc341f0662ef;p=thirdparty%2Fcups.git Just use a simple 250ms sleep in the read loop (Issue #72) --- diff --git a/CHANGES-OPENPRINTING.md b/CHANGES-OPENPRINTING.md index f799771699..67b00b82b0 100644 --- a/CHANGES-OPENPRINTING.md +++ b/CHANGES-OPENPRINTING.md @@ -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". diff --git a/backend/usb-libusb.c b/backend/usb-libusb.c index 393fe65eee..d6b0eb4232 100644 --- a/backend/usb-libusb.c +++ b/backend/usb-libusb.c @@ -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...