2007-07-18 11:55:01 +00:00
|
|
|
--- cups-1.3b1/backend/runloop.c.usb-paperout 2007-07-11 22:46:42.000000000 +0100
|
|
|
|
+++ cups-1.3b1/backend/runloop.c 2007-07-18 11:40:45.000000000 +0100
|
|
|
|
@@ -135,6 +135,14 @@
|
|
|
|
}
|
2007-04-25 17:10:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
+#ifdef __linux
|
|
|
|
+#include <sys/ioctl.h>
|
|
|
|
+#include <linux/lp.h>
|
|
|
|
+#include <time.h>
|
|
|
|
+int linux_usb_paperout_hack = 0;
|
|
|
|
+#endif /* __linux */
|
|
|
|
+
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* 'backendRunLoop()' - Read and write print and back-channel data.
|
|
|
|
*/
|
2007-07-18 11:55:01 +00:00
|
|
|
@@ -161,6 +169,9 @@
|
2007-04-25 17:10:11 +00:00
|
|
|
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
|
|
|
|
struct sigaction action; /* Actions for POSIX signals */
|
|
|
|
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
|
|
|
|
+#ifdef __linux
|
|
|
|
+ time_t last_write = 0; /* Last time write() succeeded */
|
|
|
|
+#endif /* __linux */
|
|
|
|
|
|
|
|
|
2007-07-18 11:55:01 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
@@ -210,8 +221,6 @@
|
2007-06-12 09:24:24 +00:00
|
|
|
FD_ZERO(&input);
|
|
|
|
if (!print_bytes)
|
|
|
|
FD_SET(print_fd, &input);
|
|
|
|
- if (use_bc)
|
|
|
|
- FD_SET(device_fd, &input);
|
2007-07-18 11:55:01 +00:00
|
|
|
if (side_cb)
|
|
|
|
FD_SET(CUPS_SC_FD, &input);
|
2007-06-12 09:24:24 +00:00
|
|
|
|
2007-07-18 11:55:01 +00:00
|
|
|
@@ -221,7 +230,10 @@
|
2007-06-12 09:24:24 +00:00
|
|
|
|
2007-07-18 11:55:01 +00:00
|
|
|
if (use_bc || side_cb)
|
2007-06-12 09:24:24 +00:00
|
|
|
{
|
2007-07-04 12:21:44 +00:00
|
|
|
- if (select(nfds, &input, &output, NULL, NULL) < 0)
|
|
|
|
+ struct timeval fives;
|
|
|
|
+ fives.tv_sec = 5;
|
|
|
|
+ fives.tv_usec = 0;
|
|
|
|
+ if (select(nfds, &input, &output, NULL, &fives) < 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Pause printing to clear any pending errors...
|
2007-07-18 11:55:01 +00:00
|
|
|
@@ -256,14 +268,24 @@
|
2007-06-12 09:24:24 +00:00
|
|
|
* Check if we have back-channel data ready...
|
|
|
|
*/
|
|
|
|
|
|
|
|
- if (FD_ISSET(device_fd, &input))
|
|
|
|
+ if (use_bc && FD_ISSET(device_fd, &output)) /* finished writing */
|
|
|
|
{
|
|
|
|
- if ((bc_bytes = read(device_fd, bc_buffer, sizeof(bc_buffer))) > 0)
|
|
|
|
+ struct timeval nowait;
|
|
|
|
+ fd_set readback;
|
|
|
|
+ FD_ZERO (&readback);
|
|
|
|
+ nowait.tv_sec = 0;
|
|
|
|
+ nowait.tv_usec = 0;
|
|
|
|
+ FD_SET(device_fd, &readback);
|
|
|
|
+ if (select (device_fd + 1, &readback, NULL, NULL, &nowait) &&
|
|
|
|
+ FD_ISSET(device_fd, &readback))
|
|
|
|
{
|
|
|
|
- fprintf(stderr,
|
|
|
|
- "DEBUG: Received " CUPS_LLFMT " bytes of back-channel data!\n",
|
|
|
|
- CUPS_LLCAST bc_bytes);
|
|
|
|
- cupsBackChannelWrite(bc_buffer, bc_bytes, 1.0);
|
|
|
|
+ if ((bc_bytes = read(device_fd, bc_buffer, sizeof(bc_buffer))) > 0)
|
|
|
|
+ {
|
|
|
|
+ fprintf(stderr,
|
|
|
|
+ "DEBUG: Received " CUPS_LLFMT " bytes of back-channel data!\n",
|
|
|
|
+ CUPS_LLCAST bc_bytes);
|
|
|
|
+ cupsBackChannelWrite(bc_buffer, bc_bytes, 1.0);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-18 11:55:01 +00:00
|
|
|
@@ -334,6 +356,10 @@
|
2007-07-04 12:21:44 +00:00
|
|
|
offline = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ else if (linux_usb_paperout_hack && errno == EAGAIN)
|
|
|
|
+ {
|
|
|
|
+ sleep (1);
|
|
|
|
+ }
|
|
|
|
else if (errno != EAGAIN && errno != EINTR && errno != ENOTTY)
|
|
|
|
{
|
2007-07-18 11:55:01 +00:00
|
|
|
fprintf(stderr, _("ERROR: Unable to write print data: %s\n"),
|
|
|
|
@@ -343,6 +369,9 @@
|
2007-04-25 17:10:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
+#ifdef __linux
|
|
|
|
+ last_write = time (NULL);
|
|
|
|
+#endif /* __linux */
|
|
|
|
if (paperout)
|
|
|
|
{
|
|
|
|
fputs("STATE: -media-empty-error\n", stderr);
|
2007-07-18 11:55:01 +00:00
|
|
|
@@ -363,7 +392,42 @@
|
2007-04-25 17:10:11 +00:00
|
|
|
total_bytes += bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+#ifdef __linux
|
|
|
|
+ if (linux_usb_paperout_hack)
|
|
|
|
+ {
|
|
|
|
+ time_t now;
|
|
|
|
+ if (!paperout &&
|
2007-07-04 12:21:44 +00:00
|
|
|
+ ((now = time(NULL)) - last_write) >= 5)
|
2007-04-25 17:10:11 +00:00
|
|
|
+ {
|
|
|
|
+ unsigned int status;
|
|
|
|
+ if (ioctl (device_fd, LPGETSTATUS, &status) == 0 &&
|
|
|
|
+ (status & LP_POUTPA))
|
|
|
|
+ {
|
|
|
|
+ fputs("ERROR: Out of paper!\n", stderr);
|
|
|
|
+ fputs("STATE: +media-empty-error\n", stderr);
|
|
|
|
+ paperout = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Don't check status for another 5s. */
|
|
|
|
+ last_write = now;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+#endif /* __linux */
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+#ifdef __linux
|
|
|
|
+ if (linux_usb_paperout_hack)
|
|
|
|
+ {
|
|
|
|
+ /* Wait for the last write() to finish. */
|
|
|
|
+ do
|
|
|
|
+ {
|
|
|
|
+ FD_ZERO(&output);
|
|
|
|
+ FD_SET(device_fd, &output);
|
|
|
|
+ } while (select(device_fd + 1, NULL, &output, NULL, NULL) < 0 &&
|
|
|
|
+ errno == EINTR);
|
|
|
|
}
|
|
|
|
+#endif /* __linux */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return with success...
|
2007-07-18 11:55:01 +00:00
|
|
|
--- cups-1.3b1/backend/usb-unix.c.usb-paperout 2007-07-18 11:39:32.000000000 +0100
|
|
|
|
+++ cups-1.3b1/backend/usb-unix.c 2007-07-18 11:39:32.000000000 +0100
|
|
|
|
@@ -31,6 +31,11 @@
|
2007-04-25 17:10:11 +00:00
|
|
|
#include "ieee1284.c"
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
|
|
|
+#ifdef __linux
|
|
|
|
+#include <unistd.h>
|
|
|
|
+#include <fcntl.h>
|
|
|
|
+extern int linux_usb_paperout_hack;
|
|
|
|
+#endif /* __linux */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local functions...
|
2007-07-18 11:55:01 +00:00
|
|
|
@@ -63,6 +68,11 @@
|
2007-04-25 17:10:11 +00:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
+#ifdef __linux
|
|
|
|
+ /* Get the runloop to check for USB paper-out condition. */
|
|
|
|
+ linux_usb_paperout_hack = 1;
|
|
|
|
+#endif /* __linux */
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Open the USB port device...
|
|
|
|
*/
|
2007-07-18 11:55:01 +00:00
|
|
|
@@ -156,6 +166,12 @@
|
2007-04-25 17:10:11 +00:00
|
|
|
|
|
|
|
tcsetattr(device_fd, TCSANOW, &opts);
|
|
|
|
|
|
|
|
+#ifdef __linux
|
|
|
|
+ /* Put the file descriptor into non-blocking mode so that we
|
|
|
|
+ * get a chance to detect paper-out. */
|
|
|
|
+ fcntl (device_fd, F_SETFL, fcntl (device_fd, F_GETFL) | O_NONBLOCK);
|
|
|
|
+#endif /* __linux */
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Finally, send the print file...
|
|
|
|
*/
|