Index: usb-unix.c =================================================================== --- usb-unix.c (revision 4581) +++ usb-unix.c (working copy) @@ -55,6 +55,8 @@ # endif /* __sparc */ #endif /* __sun */ +#include +#include /* * Local functions... @@ -66,7 +68,43 @@ int open_device(const char *uri); +static volatile int gDone = 0; + /* + * Post a read to the device and write results to the backchannel + */ +static void* +readthread(void *reference) +{ + int fd = (int)reference; + unsigned char readbuffer[512]; + ssize_t rbytes = 0; + fd_set fdset; + struct timeval t; + int select_result = 0; + + do + { + t.tv_sec = 1; + t.tv_usec = 0; + + FD_ZERO(&fdset); + FD_SET(fd, &fdset); + + select_result = select(fd + 1, &fdset, NULL, NULL, &t); + if (select_result > 0) + { + rbytes = read(fd, readbuffer, sizeof(readbuffer)); + if (rbytes > 0) + write(3, readbuffer, (size_t)rbytes); + } + + } while (!gDone); + + return NULL; +} + +/* * 'print_device()' - Print a file to a USB device. */ @@ -91,6 +129,8 @@ #ifdef __linux unsigned int status; /* Port status (off-line, out-of-paper, etc.) */ #endif /* __linux */ + pthread_t thr; + int thread_created = 0; /* @@ -180,6 +220,12 @@ } #endif /* __linux && LP_POUTPA */ + /* Create read thread */ + if (pthread_create(&thr, NULL, readthread, (void*)fd ) == 0) + fputs("WARNING: Couldn't create read channel\n", stderr); + else + thread_created = 1; + /* * Finally, send the print file... */ @@ -231,6 +277,13 @@ (unsigned long)tbytes); } } + + /* + * stop scheduling reads + */ + gDone = 1; + if (thread_created) + pthread_join(thr, NULL); /* * Close the USB port and return... Index: Makefile =================================================================== --- Makefile (revision 4581) +++ Makefile (working copy) @@ -152,7 +152,7 @@ usb: usb.o ../cups/$(LIBCUPS) echo Linking $@... - $(CC) $(LDFLAGS) -o usb usb.o $(BACKLIBS) $(LIBS) + $(CC) $(LDFLAGS) -o usb usb.o $(BACKLIBS) $(LIBS) -lpthread usb.o: usb.c usb-darwin.c usb-unix.c