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
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
If any help is required, or you want me to test a patch on my dev system just ask.