I want to set the SO_REUSEADDR option on a socket after the socket is initialized but before the the socket is connected. I cannot seem to make it work with the way the HTTPClientSession is designed. I want to initialize the session object with host/proxy information and be able to set SO_LINGER and SO_REUSEADDR options BEFORE the socket the session is attached to is connected, and I also want these two options to be set whenever the session decides to reconnect (due to the keepalive timeout, for example). The following code demonstrates the problem:
- Code: Select all
// Create a socket
// Configure the socket but DO NOT CONNECT!!!!
// Create a session object and attach an existing socket to it.
pSession = new Poco::Net::HTTPClientSession(ss);
pSession->setHost(uri.getHost()); // <-- throws an exception, socket is already initialized
pSession->setPort(uri.getPort()); // <-- throws an exception, socket is already initialized
pSession->setProxy(<proxy>,<proxyport); // <-- throws an exception, socket is already initialized
// finally, send/receive data using the session
Am I missing something obvious?