[cups-devel] IPP requests: Non-blocking or short timeout

Till Kamppeter till.kamppeter at gmail.com
Sun Sep 11 06:45:53 PDT 2016


Hi,

in cups-browsed I do an IPP request to a remote server like this:

----------
http_t *
httpConnectEncryptShortTimeout(const char *host, int port,
			       http_encryption_t encryption)
{
   return (httpConnect2(host, port, NULL, AF_UNSPEC, encryption, 1, 3000,
                        NULL));
}

http_t *http = NULL;
ipp_t *request, *response;
static const char *pattrs[] =
                 {
                   "printer-name",
                   "printer-state",
                   "printer-is-accepting-jobs"
                 };
http = httpConnectEncryptShortTimeout (ip ? ip : host,
				       port,
			               HTTP_ENCRYPT_IF_REQUESTED);
if (http) {
   request = ippNewRequest(CUPS_GET_PRINTERS);
   ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
	        "requested-attributes",
		sizeof(pattrs) / sizeof(pattrs[0]),
		NULL, pattrs);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
	       "requesting-user-name",
	       NULL, cupsUser());
   if ((response = cupsDoRequest(http, request, "/")) !=
       NULL) {
     ...
   }
}
----------

If the CUPS on the server is not available for some reason (but the 
server itself is available), the cupsDoRequest() call hangs and takes 
more than a minute to time out. This also blocks the shutdown via 
SIGTERM of cups-browsed.

What I would like to do is (preferably) reduce this timeout to something 
like 5 seconds. Is this possible?

What I succeded is to replace httpConnectEncrypt() by my own with a 3 
sec timeout, but this will probably only help on total absence of the 
server.

Or is the only way to use non-blocking mode? If so, is there somewhere 
sample code for doing such an IPP request non-blocking?

Thanks in advance.

    Till



More information about the cups mailing list