Overview
Features
Download
Documentation
Community
Add-Ons & Services

Problems with HTTPClientSession

A general discussion forum.

Problems with HTTPClientSession

Postby petervn » 03 Nov 2010, 21:34

Hi,

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
petervn
 
Posts: 12
Joined: 06 Oct 2009, 21:39

Re: Problems with HTTPClientSession

Postby guenter » 04 Nov 2010, 00:42

You can create a subclass of HTTPClientSession and override HTTPSession::connect().
guenter
 
Posts: 1138
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Problems with HTTPClientSession

Postby petervn » 04 Nov 2010, 02:36

guenter wrote:You can create a subclass of HTTPClientSession and override HTTPSession::connect().


Thanks for the suggestion, I actually did exactly what you are suggesting at one point but then reverted the changes as they did not have a desired effect. As it is turning out, I may have been too quick to do so. I think I've found what my problem is. I am using SO_LINGER to bypass the socket's TIME_WAIT state, but on Windows 7 setting SO_LINGER option (lingeron, time=0) has no effect (http://msdn.microsoft.com/en-us/library ... 47(v=VS.85).aspx). This used to work on Windows XP. Anyone else has observed this, I wonder?
Regards
petervn
 
Posts: 12
Joined: 06 Oct 2009, 21:39


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron