Small bug in SocketImpl...

A general discussion forum.
Posts: 6
Joined: 15 Dec 2009, 10:28

Small bug in SocketImpl...

Postby auscaster1 » 08 Mar 2010, 03:31

Hello all

It looks like these is a small bug in SocketImpl, with regards to the way the socket connection timeout works.
A sockets is initialised with timeout like so:

Code: Select all

StreamSocket ss;
ss.connect(SocketAddress(uri.getHost(), uri.getPort()), Timespan(2000000));

The desired result is that a TimeoutException exception will be raised after 2 seconds if the connection fails, but in reality it is more like 10 seconds, and the exception never throws, so it seems that the timeout is not being honored.

I seem to have isolated the problem, though it is beyond my ability to provide a proper solution.
The SocketImpl code is like this:

Code: Select all

int rc = ::connect(_sockfd, address.addr(), address.length());
if (rc != 0)
   if (lastError() != POCO_EINPROGRESS && lastError() != POCO_EWOULDBLOCK)
   if (!poll(timeout, SELECT_READ | SELECT_WRITE))
      throw Poco::TimeoutException("connect timed out", address.toString());
   int err = socketError();
   if (err != 0) error(err);

The non blocking socket connect and the call to poll is made properly, but problem is that the return value from poll is always true so no exception is thrown.
It is also worth noting that poll delays the correct duration of 2 seconds, with an internal 'rc' value (set by the select() call) of 1 before returning.

I am running windows XP with the latest poco release 1.3.6, so it's probably some obscure windows socket idiosyncrasy that is causing this.
A solution for this would be most welcome as my app checks for an internet connection on startup, effectively adding 10 seconds to the startup time :lol:

If any help is required, or you want me to test a patch on my dev system just ask.


Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Small bug in SocketImpl...

Postby guenter » 09 Mar 2010, 18:58

I'll have to look into this. I created a bug report in the meantime: ... tid=725709

Posts: 6
Joined: 15 Dec 2009, 10:28

Re: Small bug in SocketImpl...

Postby auscaster1 » 15 Mar 2010, 06:34

Thanks guenter,

I'll be following the progress.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest