From: msweet Date: Thu, 30 May 2013 01:33:55 +0000 (+0000) Subject: ipptool: Use SO_NWRITE socket option to extend timeouts X-Git-Tag: release-1.7rc1~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26340b35e86087d3896d6b8e8a8480e7f4c9c53d;p=thirdparty%2Fcups.git ipptool: Use SO_NWRITE socket option to extend timeouts Make the ipptool timeout callback check whether the output buffer is empty. If not, automatically extend the timeout until it is - useful for when the printer is blocking due to a printer error like "out of paper"... git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@11000 a1ca3aef-8c08-0410-bb20-df032aa958be --- diff --git a/CHANGES-IPPTOOL.txt b/CHANGES-IPPTOOL.txt index 0fc2078484..9c0a36fe09 100644 --- a/CHANGES-IPPTOOL.txt +++ b/CHANGES-IPPTOOL.txt @@ -1,11 +1,14 @@ -CHANGES-IPPTOOL.txt - 2013-05-02 +CHANGES-IPPTOOL.txt - 2013-05-29 -------------------------------- This file provides a list of changes to the ipptool binary distribution posted on cups.org. -2013-05-02 +2013-05-29 + - Added support for automatically extending the timeout when all of the + request data has not yet been written (all platforms but Windows + which does not support it...) - Fixed several ipptool test files that used old STATUS names. diff --git a/CHANGES.txt b/CHANGES.txt index bf59c88f30..a6e87ebf0a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,6 +3,8 @@ CHANGES.txt - 1.7b1 - 2013-05-13 CHANGES IN CUPS V1.7b2 + - The ipptool program now automatically extends timeouts when the + output buffer is filled () - The ipptool program now supports the --help and --version options. - The ipptool program did not continue past include file errors by default () diff --git a/test/ipptool.c b/test/ipptool.c index 9d6044604e..bb101ae3f1 100644 --- a/test/ipptool.c +++ b/test/ipptool.c @@ -4744,14 +4744,34 @@ sigterm_handler(int sig) /* I - Signal number (unused) */ */ static int /* O - 1 to continue, 0 to cancel */ -timeout_cb(http_t *http, /* I - Connection to server (unused) */ +timeout_cb(http_t *http, /* I - Connection to server */ void *user_data) /* I - User data (unused) */ { + int buffered = 0; /* Bytes buffered but not yet sent */ + + + /* + * If the socket still have data waiting to be sent to the printer (as can + * happen if the printer runs out of paper), continue to wait until the output + * buffer is empty... + */ + +#ifdef SO_NWRITE /* OS X and some versions of Linux */ + socklen_t len = sizeof(buffered); /* Size of return value */ + + if (getsockopt(httpGetFd(http), SOL_SOCKET, SO_NWRITE, &buffered, &len)) + buffered = 0; + +#elif defined(SIOCOUTQ) /* Others except Windows */ + if (ioctl(httpGetFd(http), SIOCOUTQ, &buffered)) + buffered = 0; + +#else /* Windows (not possible) */ (void)http; (void)user_data; +#endif /* SO_NWRITE */ - /* Always cancel on timeout */ - return (0); + return (buffered > 0); }