MCPcopy Create free account
hub / github.com/OpenPrinting/cups / read_thread

Function read_thread

backend/usb-libusb.c:1821–1873  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1819 */
1820
1821static void *read_thread(void *reference)
1822{
1823 unsigned char readbuffer[512];
1824 int rbytes;
1825 int readstatus;
1826
1827
1828 (void)reference;
1829
1830 do
1831 {
1832 /*
1833 * Try reading from the OUT (to host) endpoint...
1834 */
1835
1836 rbytes = sizeof(readbuffer);
1837 readstatus = libusb_bulk_transfer(g.printer->handle,
1838 g.printer->read_endp,
1839 readbuffer, rbytes,
1840 &rbytes, 60000);
1841 if (readstatus == LIBUSB_SUCCESS && rbytes > 0)
1842 {
1843 fprintf(stderr, "DEBUG: Read %d bytes of back-channel data...\n", (int)rbytes);
1844 cupsBackChannelWrite((const char *)readbuffer, (size_t)rbytes, 1.0);
1845 }
1846 else if (readstatus == LIBUSB_ERROR_TIMEOUT)
1847 fputs("DEBUG: Got USB transaction timeout during read.\n", stderr);
1848 else if (readstatus == LIBUSB_ERROR_PIPE)
1849 fputs("DEBUG: Got USB pipe stalled during read.\n", stderr);
1850 else if (readstatus == LIBUSB_ERROR_INTERRUPTED)
1851 fputs("DEBUG: Got USB return aborted during read.\n", stderr);
1852
1853 /*
1854 * Make sure this loop executes no more than once every 250 milliseconds...
1855 */
1856
1857 if ((readstatus != LIBUSB_SUCCESS || rbytes == 0) &&
1858 (g.wait_eof || !g.read_thread_stop))
1859 usleep(250000);
1860 }
1861 while (g.wait_eof || !g.read_thread_stop);
1862
1863 /*
1864 * Let the main thread know that we have completed the read thread...
1865 */
1866
1867 pthread_mutex_lock(&g.read_thread_mutex);
1868 g.read_thread_done = 1;
1869 pthread_cond_signal(&g.read_thread_cond);
1870 pthread_mutex_unlock(&g.read_thread_mutex);
1871
1872 return (NULL);
1873}
1874
1875
1876/*

Callers

nothing calls this directly

Calls 1

cupsBackChannelWriteFunction · 0.85

Tested by

no test coverage detected