Closed michaelrsweet closed 18 years ago
CUPS.org User: mike
OK, attached is the first part of a patch that addresses the back-channel data problems - it covers all but the serial backend. Part 2 will update the serial backend.
CUPS.org User: mike
Fixed in Subversion repository.
"str1724p1.patch":
--- runloop.c (revision 0) +++ runloop.c (revision 0) @@ -0,0 +1,218 @@ +/*
Property changes on: runloop.c
Name: svn:keywords
--- test1284.c (revision 5589) +++ test1284.c (working copy) @@ -41,6 +41,7 @@
+
@@ -76,8 +77,8 @@
printf("%s:\n", argv[i]);
sizeof(make_model), "test", uri, sizeof(uri));
printf(" device_id=\"%s\"\n", device_id); printf(" make_model=\"%s\"\n", make_model);
--- backend-private.h (revision 0) +++ backend-private.h (revision 0) @@ -0,0 +1,73 @@ +/*
Property changes on: backend-private.h
Name: svn:keywords
--- Dependencies (revision 5589) +++ Dependencies (working copy) @@ -9,26 +9,31 @@ lpd.o: ../cups/md5.h ../cups/ipp-private.h ../cups/ipp.h ../cups/cups.h lpd.o: ../cups/ppd.h ../cups/array.h ../cups/file.h ../cups/language.h lpd.o: ../cups/string.h -parallel.o: ../cups/backend.h ../cups/cups.h ../cups/ipp.h ../cups/http.h -parallel.o: ../cups/md5.h ../cups/ppd.h ../cups/array.h ../cups/file.h -parallel.o: ../cups/language.h ../cups/string.h ../config.h ieee1284.c -parallel.o: ../cups/debug.h +pap.o: ../cups/http.h ../cups/md5.h +parallel.o: backend-private.h ../cups/backend.h ../cups/cups.h ../cups/ipp.h +parallel.o: ../cups/http.h ../cups/md5.h ../cups/ppd.h ../cups/array.h +parallel.o: ../cups/file.h ../cups/language.h ../cups/debug.h +parallel.o: ../cups/string.h ../config.h scsi.o: ../cups/backend.h ../cups/cups.h ../cups/ipp.h ../cups/http.h scsi.o: ../cups/md5.h ../cups/ppd.h ../cups/array.h ../cups/file.h scsi.o: ../cups/language.h ../cups/string.h ../config.h -serial.o: ../cups/backend.h ../cups/cups.h ../cups/ipp.h ../cups/http.h -serial.o: ../cups/md5.h ../cups/ppd.h ../cups/array.h ../cups/file.h -serial.o: ../cups/language.h ../cups/string.h ../config.h -snmp.o: ../cups/backend.h ../cups/http-private.h ../config.h ../cups/http.h -snmp.o: ../cups/md5.h ../cups/ipp-private.h ../cups/ipp.h ../cups/cups.h -snmp.o: ../cups/ppd.h ../cups/array.h ../cups/file.h ../cups/language.h -snmp.o: ../cups/string.h ../cups/array.h ../cups/file.h ieee1284.c -snmp.o: ../cups/debug.h -socket.o: ../cups/backend.h ../cups/http-private.h ../config.h ../cups/http.h -socket.o: ../cups/md5.h ../cups/ipp-private.h ../cups/ipp.h ../cups/cups.h -socket.o: ../cups/ppd.h ../cups/array.h ../cups/file.h ../cups/language.h -socket.o: ../cups/string.h -test1284.o: ../cups/string.h ../config.h ieee1284.c ../cups/debug.h +serial.o: backend-private.h ../cups/backend.h ../cups/cups.h ../cups/ipp.h +serial.o: ../cups/http.h ../cups/md5.h ../cups/ppd.h ../cups/array.h +serial.o: ../cups/file.h ../cups/language.h ../cups/debug.h ../cups/string.h +serial.o: ../config.h +snmp.o: ../cups/http-private.h ../config.h ../cups/http.h ../cups/md5.h +snmp.o: ../cups/ipp-private.h ../cups/ipp.h backend-private.h +snmp.o: ../cups/backend.h ../cups/cups.h ../cups/ppd.h ../cups/array.h +snmp.o: ../cups/file.h ../cups/language.h ../cups/debug.h ../cups/string.h +snmp.o: ../cups/array.h ../cups/file.h +socket.o: ../cups/http-private.h ../config.h ../cups/http.h ../cups/md5.h +socket.o: ../cups/ipp-private.h ../cups/ipp.h backend-private.h +socket.o: ../cups/backend.h ../cups/cups.h ../cups/ppd.h ../cups/array.h +socket.o: ../cups/file.h ../cups/language.h ../cups/debug.h ../cups/string.h +test1284.o: ../cups/string.h ../config.h ieee1284.c backend-private.h +test1284.o: ../cups/backend.h ../cups/cups.h ../cups/ipp.h ../cups/http.h +test1284.o: ../cups/md5.h ../cups/ppd.h ../cups/array.h ../cups/file.h +test1284.o: ../cups/language.h ../cups/debug.h usb.o: ../cups/backend.h ../cups/cups.h ../cups/ipp.h ../cups/http.h usb.o: ../cups/md5.h ../cups/ppd.h ../cups/array.h ../cups/file.h usb.o: ../cups/language.h ../cups/string.h ../config.h
--- usb-unix.c (revision 5589) +++ usb-unix.c (working copy) @@ -55,31 +55,21 @@ const char hostname, / I - Hostname/manufacturer / const char *resource, / I - Resource/modelname / const char *options, / I - Device options/serial number */
int fp, /* I - File descriptor to print */
int printfd, /* I - File descriptor to print / int copies, / I - Copies to print / int argc, / I - Number of command-line arguments (6 or 7) / char argv[]) /_ I - Command-line arguments / {
int usebc; /* Use backchannel path? */
int fd; /* USB device */
int rbytes; /* Number of bytes read */
int wbytes; /* Number of bytes written */
size_t nbytes, /* Number of bytes read */
tbytes; /* Total number of bytes written */
char buffer[8192], /* Output buffer */
bufptr, / Pointer into buffer */
backbuf[1024]; /* Backchannel buffer */
int use_bc; /* Use backchannel path? */
int device_fd; /* USB device */
sizet tbytes; /* Total number of bytes written / struct termios opts; /_ Parallel port options */
fd_set input, /* Input set for select() */
output; /* Output set for select() */
int paperout; /* Paper out? */ -#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals / -#endif / HAVE_SIGACTION && !HAVESIGSET / -#ifdef linux +#if defined(linux) && defined(LPPOUTPA) unsigned int status; / Port status (off-line, out-of-paper, etc.) / -#endif / __linux */
int paperout; /* Paper out? / +#endif / __linux && LP_POUTPA */
(void)argc; (void)argv;
@@ -89,7 +79,7 @@
use_bc = strcasecmp(hostname, "Canon") != 0;
/*
do {
while (device_fd < 0);
fputs("STATE: -connecting-to-device\n", stderr);
@@ -148,28 +139,25 @@
tcgetattr(device_fd, &opts);
opts.c_lflag &= ~(ICANON | ECHO | ISIG); /* Raw mode */
/\ No options supported yet **/
/*
status);
if (status & LP_POUTPA) { @@ -191,146 +179,35 @@
/*
lseek(print_fd, 0, SEEK_SET);
}
tbytes += nbytes;
CUPS_LLCAST tbytes);
}
/*
@@ -372,9 +249,9 @@
if ((fd = open(device, O_RDWR | O_EXCL)) >= 0)
{
@@ -401,9 +278,9 @@
if ((fd = open(device, O_RDWR | O_EXCL)) >= 0)
{
@@ -486,9 +363,9 @@
if ((fd = open(device, O_RDWR | O_EXCL)) >= 0)
{
"usb", device_uri, sizeof(device_uri));
} else { @@ -572,9 +449,9 @@ sprintf(device, "/dev/usb/printer%d", i);
if ((fd = open(device, O_RDWR | O_EXCL)) >= 0)
--- snmp.c (revision 5589) +++ snmp.c (working copy) @@ -77,19 +77,12 @@
-#include <cups/backend.h>
-#include <cups/cups.h> -#include <cups/string.h> +#include "backend-private.h"
-#include
-#define SNMP_BACKEND -#include "ieee1284.c"
/*
based approach to get SNMP response packets from potential printers @@ -1656,7 +1649,7 @@ if (model) strlcpy(temp, model->values[0].string.text, sizeof(temp)); else if (info)
backendGetMakeModel(info->values[0].string.text, temp, sizeof(temp));
fix_make_model(make_model, temp, sizeof(make_model));
@@ -1928,8 +1921,8 @@ * Description is the IEEE-1284 device ID... */
--- serial.c (revision 5589) +++ serial.c (working copy) @@ -33,13 +33,7 @@
-#include <cups/backend.h>
-#include <cups/cups.h>
-#include
--- ieee1284.c (revision 5589) +++ ieee1284.c (working copy) @@ -25,51 +25,41 @@ *
Contents: *
/*
-#include <cups/debug.h> +#include "backend-private.h"
+#ifdef linux +# include <sys/ioctl.h> +# include <linux/lp.h> +# define IOCNR_GET_DEVICE_ID 1 +# define LPIOC_GET_DEVICE_ID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len) +#endif /* linux */
-/*
-static int get_make_model(const char device_id, char make_model,
/*
-#ifndef SNMP_BACKEND -# ifdef __linux -# include <sys/ioctl.h> -# include <linux/lp.h> -# define IOCNR_GET_DEVICE_ID 1 -# define LPIOC_GET_DEVICE_ID(len) _IOC(_IOC_READ, 'P', IOCNR_GET_DEVICE_ID, len)
-# ifdef sun -# ifdef sparc -# include <sys/ecppio.h> -# else -# include <sys/ioccom.h> -# include <sys/ecppsys.h> -# endif /* __sparc */
int /* O - 0 on success, -1 on failure _/ -get_deviceid( +backendGetDeviceID( int fd, / I - File descriptor _/ char *deviceid, / O - 1284 device ID _/ int device_idsize, / I - Size of buffer _/ @@ -93,7 +83,7 @@
@@ -155,7 +145,7 @@ }
else
@@ -178,11 +168,11 @@ }
else
printf("backendGetDeviceID: ioctl failed - %s\n", strerror(errno));
DEBUG_printf(("backendGetDeviceID: device_id=\"%s\"\n", device_id));
if (!*device_id) return (-1); @@ -191,7 +181,7 @@
backendGetMakeModel(device_id, make_model, make_model_size);
/*
return (0); } -#endif /* !SNMP_BACKEND */
/*
int /* O - 0 on success, -1 on failure _/ -get_make_model( +backendGetMakeModel( const char deviceid, / O - 1284 device ID _/ char makemodel, / O - Make/model _/ int make_modelsize) / I - Size of buffer / @@ -322,7 +311,7 @@ *mdl; / Model string */
@@ -332,7 +321,7 @@
if (!device_id || !*device_id || !make_model || make_model_size < 32) {
--- socket.c (revision 5589) +++ socket.c (working copy) @@ -32,17 +32,11 @@
-#include <cups/backend.h>
-#include <cups/cups.h>
-#include
-#include <cups/string.h>
-#include
-#include
@@ -76,24 +70,19 @@ name[255], /* Name of option / value[255], / Value of option / *ptr; / Pointer into name or value */
ssize_t bcbytes; /* Number of back-channel bytes read /
struct sigaction action; / Actions for POSIX signals /
@@ -142,8 +131,8 @@
if (argc == 6) {
hostname);
fprintf(stderr, "INFO: Unable to connect to \"%s\", queuing on next printer in class...\n",
sleep(5);
}
return (CUPS_BACKEND_FAILED);
sigemptyset(&action.sa_mask);
lseek(print_fd, 0, SEEK_SET);
}
tbytes += nbytes;
while (nbytes > 0)
do
if (FD_ISSET(fd, &input))
* connection...
*/
fputs("INFO: Print file sent, waiting for printer to finish...\n", stderr);
timeout.tv_usec = 0;
shutdown(fd, 1);
FD_SET(device_fd, &input);
for (;;)
+#ifdef __hpux
close(device_fd);
httpAddrFreeList(addrlist);
@@ -481,13 +376,13 @@
--- usb.c (revision 5589) +++ usb.c (working copy) @@ -63,7 +63,7 @@ void list_devices(void); int print_device(const char uri, const char hostname, const char resource, const char options,
int print_fd, int copies, int argc, char *argv[]);
/ @@ -108,7 +108,7 @@ const char hostname, / I - Hostname/manufacturer _/ const char resource, / I - Resource/modelname / const char options, /_ I - Device options/serial number /
int printfd; /* Print file / int copies; / Number of copies to print / int status; / Exit status / int port; /_ Port number (not used) */ @@ -232,8 +232,8 @@
if (argc == 6) {
argc, argv);
/*
close(print_fd);
return (status); }
--- parallel.c (revision 5589) +++ parallel.c (working copy) @@ -33,14 +33,7 @@
-#include <cups/backend.h>
-#include <cups/cups.h>
-#include
@@ -94,25 +87,20 @@ resource[1024], /* Resource info (device and options) / *options; / Pointer to options / int port; / Port number (not used) */
struct sigaction action; / Actions for POSIX signals /
-#ifdef __linux
unsigned int status; /* Port status (off-line, out-of-paper, etc.) / -#endif / __linux */
/* @@ -157,8 +145,8 @@
if (argc == 6) {
if ((print_fd = open(argv[6], O_RDONLY)) < 0) { perror("ERROR: unable to open print file"); return (CUPS_BACKEND_FAILED); @@ -206,7 +194,7 @@
do {
fputs("INFO: Unable to open parallel port, queuing on next printer in class...\n",
"in class...\n", stderr);
/*
* Sleep 5 seconds to keep the job from requeuing too rapidly...
@@ -231,23 +219,26 @@
if (errno == EBUSY) {
while (device_fd < 0);
fputs("STATE: -connecting-to-device\n", stderr);
@@ -255,25 +246,21 @@
tcgetattr(device_fd, &opts);
opts.c_lflag &= ~(ICANON | ECHO | ISIG); /* Raw mode */
/\ No options supported yet **/
/*
paperout = 0; + while (!ioctl(fd, LPGETSTATUS, &status)) { fprintf(stderr, "DEBUG: LPGETSTATUS returned a port status of %02X...\n", status); @@ -298,146 +285,38 @@
/*
lseek(print_fd, 0, SEEK_SET);
}
tbytes += nbytes;
CUPS_LLCAST tbytes);
}
/*
@@ -485,9 +364,9 @@ * Now grab the IEEE 1284 device ID string... */
NULL, NULL, 0))
printf("direct parallel:%s \"%s\" \"%s LPT #%d\" \"%s\"\n", device, make_model, make_model, i + 1, device_id); else
--- Makefile (revision 5589) +++ Makefile (working copy) @@ -28,7 +28,8 @@
RBACKENDS = ipp lpd UBACKENDS = $(PAP) parallel scsi serial snmp socket usb -TARGETS = betest test1284 $(RBACKENDS) $(UBACKENDS) +TARGETS = betest test1284 libbackend.a $(RBACKENDS) $(UBACKENDS) +LIBOBJS = ieee1284.o runloop.o OBJS = betest.o ipp.o lpd.o pap.o parallel.o scsi.o \ serial.o snmp.o socket.o test1284.o usb.o
@@ -105,6 +106,17 @@
# +# libbackend.a +# + +libbackend.a: $(LIBOBJS)
#
@@ -149,9 +161,9 @@
#
-parallel: parallel.o ../cups/$(LIBCUPS) +parallel: parallel.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...
$(CC) $(LDFLAGS) -o parallel parallel.o libbackend.a $(LIBS)
# @@ -169,37 +181,37 @@
#
-serial: serial.o ../cups/$(LIBCUPS) +serial: serial.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...
$(CC) $(LDFLAGS) -o serial serial.o libbackend.a $(BACKLIBS) $(LIBS)
#
#
-snmp: snmp.o ../cups/$(LIBCUPS) +snmp: snmp.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...
$(CC) $(LDFLAGS) -o snmp snmp.o libbackend.a $(LIBS)
#
#
-socket: socket.o ../cups/$(LIBCUPS) +socket: socket.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...
$(CC) $(LDFLAGS) -o socket socket.o libbackend.a $(LIBS)
#
#
-usb: usb.o ../cups/$(LIBCUPS) +usb: usb.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...
$(CC) $(LDFLAGS) -o usb usb.o libbackend.a $(BACKLIBS) $(LIBS) +usb.o: usb.c usb-darwin.c usb-unix.c
#
Version: 1.2.0 CUPS.org User: joshmathis
It appears that the USB backend is not fetching the data from the printer until the printer driver (filter) has exited (in most cases).
As a test, I modified my filter to just send a status request to the printer. The printer should return 1 byte in reponse, which I attempt to read, then exit the filter.
In the error log, I see:
[Job xx] MY Debug Wrote status request [Job xx] MY Debug Read -1 backchannel bytes PID # (my filter) has exited with no errors. [Job xx] *****DEBUG: Received 1 bytes of back-channel data!
I set up my filter to try 10 backchannel reads in a row before finally giving up.
I tried flushing stdout and stderr after every printf to each of those streams, but with no effect. I then disabled all stream buffering with:
setbuf(stdout, NULL); setbuf(stderr, NULL); //and for good measure: setbuf(stdin, NULL);
After this, the second out of my 10 backchannel reads gets the data back correctly. No matter the timeout, etc, the first backchannel read will fail, and the second one seems to always work.