fix timeout by checking the socket for errors
In the old situation when the connect didn't immediately return, the socket was placed in a select. An error was throws only when the socket was in the exceptset. However, sockets are only in the exceptset in very particular cases (see man select). Unable to connect is not one of those cases.
Therefore to actually check if a connection was refused, the error status must be checked with getsockopt.