diff -Naur cups-1.6svn-r10486.orig/cups/request.c cups-1.6svn-r10486/cups/request.c --- cups-1.6svn-r10486.orig/cups/request.c 2012-05-12 02:07:16.000000000 +0200 +++ cups-1.6svn-r10486/cups/request.c 2012-09-12 09:16:21.888777664 +0200 @@ -46,7 +46,9 @@ #ifndef O_BINARY # define O_BINARY 0 #endif /* O_BINARY */ - +#if defined(__sun) +#include /* need this for TCPS_ESTABLISHED ... */ +#endif /* * 'cupsDoFileRequest()' - Do an IPP request with a file. @@ -1000,6 +1002,38 @@ } } +#if defined(__sun) + /* + * Check the connection state. + * If the connection wasn't used for some time, the server could close it. + * The socket state would change to CLOSE_WAIT in such case. + */ + if (cg->http) + { + struct tcp_info tcpi; + socklen_t len = sizeof(tcpi); + memset(&tcpi, 0, sizeof(tcpi)); + + /* + * Get TCP connection info. + */ + if (getsockopt(cg->http->fd, IPPROTO_TCP, TCP_INFO, &tcpi, &len) == 0) + { + /* + * Successfully got TCP connection state. Check it. + */ + if (tcpi.tcpi_state != TCPS_ESTABLISHED) + { + /* + * Need to close the current connection. + */ + httpClose(cg->http); + cg->http = NULL; + } + } + } +#endif + /* * (Re)connect as needed... */