apple / cups

Apple CUPS Sources
https://www.cups.org
Apache License 2.0
1.95k stars 464 forks source link

Backchannel data is not read right away #1724

Closed michaelrsweet closed 18 years ago

michaelrsweet commented 18 years ago

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.

michaelrsweet commented 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.

michaelrsweet commented 18 years ago

CUPS.org User: mike

Fixed in Subversion repository.

michaelrsweet commented 18 years ago

"str1724p1.patch":

Index: runloop.c

--- runloop.c (revision 0) +++ runloop.c (revision 0) @@ -0,0 +1,218 @@ +/*

Property changes on: runloop.c


Name: svn:keywords

Index: test1284.c

--- test1284.c (revision 5589) +++ test1284.c (working copy) @@ -41,6 +41,7 @@

include

include

endif /* WIN32 */

+

define DEBUG

include "ieee1284.c"

@@ -76,8 +77,8 @@

 printf("%s:\n", argv[i]);

Property changes on: backend-private.h


Name: svn:keywords

Index: Dependencies

--- 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

Index: usb-unix.c

--- 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 */

@@ -89,7 +79,7 @@

@@ -148,28 +139,25 @@

- */

- paperout = 0;

if defined(__linux) && defined(LP_POUTPA)

/*

- */

- memset(&action, 0, sizeof(action));

- }

- bufptr = buffer;

- */

- FD_SET(fd, &input);

- while (select(fd + 1, &input, &output, NULL, NULL) < 0);

- */

- }

- */

- wbytes = write(fd, bufptr, nbytes);

- */

- */

- }

- }

- break;

@@ -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)
{

-#include <cups/backend.h>

include <cups/http-private.h>

-#include <cups/cups.h> -#include <cups/string.h> +#include "backend-private.h"

include <cups/array.h>

include <cups/file.h>

-#include -#include

-#define SNMP_BACKEND -#include "ieee1284.c"

/*

@@ -1928,8 +1921,8 @@ * Description is the IEEE-1284 device ID... */

-#include <cups/backend.h> -#include <cups/cups.h> -#include -#include -#include -#include <cups/string.h> -#include +#include "backend-private.h"

ifdef __hpux

include <sys/modem.h>

Index: ieee1284.c

--- ieee1284.c (revision 5589) +++ ieee1284.c (working copy) @@ -25,51 +25,41 @@ *

-#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)

-# endif /* __linux */

-# ifdef sun -# ifdef sparc -# include <sys/ecppio.h> -# else -# include <sys/ioccom.h> -# include <sys/ecppsys.h> -# endif /* __sparc */

-# endif /* __sun */

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 @@

endif /_ __sun && ECPPIOC_GETDEVID */

@@ -155,7 +145,7 @@ }

ifdef DEBUG

else

@@ -178,11 +168,11 @@ }

ifdef DEBUG

else

@@ -332,7 +321,7 @@

if (!device_id || !*device_id || !make_model || make_model_size < 32) {

Index: socket.c

--- socket.c (revision 5589) +++ socket.c (working copy) @@ -32,17 +32,11 @@

-#include <cups/backend.h>

include <cups/http-private.h>

-#include <cups/cups.h> -#include -#include +#include "backend-private.h"

include

-#include <cups/string.h> -#include

include <sys/types.h>

include <sys/stat.h>

-#include

ifdef WIN32

include

@@ -76,24 +70,19 @@ name[255], /* Name of option / value[255], / Value of option / *ptr; / Pointer into name or value */

- fputs("STATE: +connecting-to-device\n", stderr);

- sleep(delay);

- }

- */

- */

- }

- */

- */

- */

- }

- break;

- }

- timeout.tv_usec = 0;

- FD_SET(fd, &input);

- */

@@ -481,13 +376,13 @@

Index: usb.c

--- 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,

-#include <cups/backend.h> -#include <cups/cups.h> -#include -#include -#include -#include <cups/string.h> -#include -#include "ieee1284.c" +#include "backend-private.h"

ifdef __hpux

include <sys/time.h>

@@ -94,25 +87,20 @@ resource[1024], /* Resource info (device and options) / *options; / Pointer to options / int port; / Port number (not used) */

@@ -255,25 +246,21 @@

- */

- paperout = 0;

if defined(__linux) && defined(LP_POUTPA)

/*

- */

- memset(&action, 0, sizeof(action));

- }

- bufptr = buffer;

- */

- while (select(fd + 1, &input, &output, NULL, NULL) < 0);

- */

- }

- */

- wbytes = write(fd, bufptr, nbytes);

- */

- */

- }

- }

- break;

@@ -485,9 +364,9 @@ * Now grab the IEEE 1284 device ID string... */

@@ -105,6 +106,17 @@

# +# libbackend.a +# + +libbackend.a: $(LIBOBJS)

@@ -149,9 +161,9 @@

parallel

#

-parallel: parallel.o ../cups/$(LIBCUPS) +parallel: parallel.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...

-serial: serial.o ../cups/$(LIBCUPS) +serial: serial.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...

-snmp: snmp.o ../cups/$(LIBCUPS) +snmp: snmp.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...

-socket: socket.o ../cups/$(LIBCUPS) +socket: socket.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...

-usb: usb.o ../cups/$(LIBCUPS) +usb: usb.o ../cups/$(LIBCUPS) libbackend.a echo Linking $@...