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
Poco::URI uri;
...
// Create a socket
Poco::Net::StreamSocket ss(Poco::IPAddress::IPv4);
// Configure the socket but DO NOT CONNECT!!!!
ss.setReuseAddress(true);
ss.setLinger(true, 0);
// 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
pSession->sendRequest(...);
pSession->receiveResponse(...);
Am I missing something obvious?
Thanks





