Need better timeout control in client library

Michael Sweet mike at easysw.com
Thu Apr 6 08:32:50 PDT 2006


dank at kegel.com wrote:
> We have a Linux box which hangs mysteriously when
> the app calls cupsGetDests to get a list of printers.
> 
> Turns out the connect to the localhost's CUPS daemon
> is hanging in state SYN_SENT because there is
> some firewall setting causing SYN packets to be
> dropped.  This is not a common situation, but
> it does happen once in a while.

Sounds like a firewall bug, but the client connection *should*
timeout after 300 seconds...

> It would be nice if the cups client library provided
> a way to test the connection to the default
> server, e.g.
>   cupsStartConnect();
>   cupsFinishConnect(bool wait, int timeout_in_seconds);
> Then the app could start a nonblocking connect
> on startup, and check for connection completion
> at its leisure without freezing its UI.
> 
> How's that sound?

Sounds like an asynchronous httpConnect() method, and right now we
don't have it...  We're looking at this for CUPS 1.3, however there
are some major issues to deal with such as asynchronous connections
being incredibly non-portable...

You can use alarm() along with a signal handler to put a shorter
connection timeout in the application; I would recommend using
cupsGetDests2() instead of cupsGetDests() and using alarm() with a
call to httpConnectEncrypt(), e.g.:

     signal(SIGALRM, SIG_IGN);

     alarm(30);

     http = httpConnectEncrypt(cupsServer(), ippPort(),
                               cupsEncryption());

     alarm(0);

     if (http)
     {
       num_dests = cupsGetDests2(http, &dests);
       httpClose(http);
     }
     else
       num_dests = 0;

-- 
______________________________________________________________________
Michael Sweet, Easy Software Products           mike at easysw dot com
Internet Printing and Document Software          http://www.easysw.com




More information about the cups mailing list