Overview
Features
Download
Documentation
Community
Add-Ons & Services

SocketConnector

Please post support and help requests here.

SocketConnector

Postby dvk » 28 May 2008, 16:59

I am experimenting with the Socketconnector class.

I noticed that when the socket connection fails, it will trigger the onError callback, but in the next SocketReactor run cycle

Socket::select(readable, writable, except, _timeout)

throws an error, which causes the socketreactor thread (it was started in its own thread) to stop running. Is this the desired behavior?

Does that mean every Socketconnector instance needs its own dedicated SocketReactor?

And finally another question, in most papers where the connector-adaptor pattern is described, it is possible to have multiple ServiceHandlers connected to one Connector. Am I correct to assume that in the Poco implementation a socketconnector can only instantiate one ServiceHandler? (Since the connect can only happen in the SocketConnector constructor)
dvk
 
Posts: 5
Joined: 13 Dec 2007, 12:23
Location: Belgium

Re: SocketConnector

Postby dvk » 29 May 2008, 14:41

When you call Socket::select with 0 sockets, it will throw an exception. Shouldn't it just return 0 in that case? The docs state : "Returns the number of sockets ready."

Calling Socket::select with empty SocketLists is not useful, but it can happen. eg. You create a SocketReactor, and start it before adding the first SocketConnector is registered. Or the only ServiceHandler connected to a SocketReactor is closed by the remote host, causing the EventHandlers to be removed from the SocketReactor.

In these cases you arrive in a state where you think the SocketReactor is still running, but the run function has quit.

I am wondering if this is intended, and if so what is the appropriate way (order) to handle the above scenarios?
dvk
 
Posts: 5
Joined: 13 Dec 2007, 12:23
Location: Belgium

Re: SocketConnector

Postby guenter » 29 May 2008, 16:46

This could well be a bug. I will investigate it next week (I am a bit stressed at the moment...)
guenter
 
Posts: 1121
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Re: SocketConnector

Postby dvk » 05 Jun 2008, 08:36

> This could well be a bug. I will investigate it next week (I am a bit stressed at the moment...)

Until you had a chance to look into this problem, I have patched Socket::select in the socket.cpp file like this :

^
for (SocketList::const_iterator it = exceptList.begin(); it != exceptList.end(); ++it)

{

if (int(it->sockfd()) > nfd)

nfd = int(it->sockfd());
FD_SET(it->sockfd(), &fdExcept);
}

//ADDED CODE
if (fdRead.fd_count == 0 && fdWrite.fd_count == 0 && fdExcept.fd_count == 0)
return 0;
//END ADDED CODE

Poco::Timespan remainingTime(timeout);
^
I don't know if it is a valid fix, I didn't really check if it breaks other things, but with this code a socketreactor thread isn't quit when a connection error occurs on the only socketconnector.
dvk
 
Posts: 5
Joined: 13 Dec 2007, 12:23
Location: Belgium

Re: SocketConnector

Postby guenter » 21 Sep 2008, 20:22

This is fixed in 1.3.3. Socket::select() can now be called with all sets empty. Also, SocketReactor has a new IdleNotification, posted when the SocketReactor has no sockets to handle in run().
guenter
 
Posts: 1121
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests