summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorGraham Fawcett <fawcett@uwindsor.ca>2018-03-28 19:09:16 -0400
committerGraham Fawcett <fawcett@uwindsor.ca>2018-03-28 19:09:16 -0400
commitace96bf83e711438d517bec33e5d83f27e352726 (patch)
tree72718d3410b40b370a36cdaab30e286d331430dc
parent50229293ae5898acc2c30f9cb87b59e2fa0b236a (diff)
downloadNim-ace96bf83e711438d517bec33e5d83f27e352726.tar.gz
net.connect (with timeout), raise error on connect failure
Under Linux (probably POSIX), the current code tests for timeout, but
does not test for connection failure. connectAsync() returns succesfully
upon an EINPROGRESS result; but at this point, the connection state is
still unknown. After selectWrite() is done, we need to test the socket
for errors again.
-rw-r--r--lib/pure/net.nim3
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/pure/net.nim b/lib/pure/net.nim
index af9eea51a..2d1ca8a59 100644
--- a/lib/pure/net.nim
+++ b/lib/pure/net.nim
@@ -1664,6 +1664,9 @@ proc connect*(socket: Socket, address: string, port = Port(0),
   if selectWrite(s, timeout) != 1:
     raise newException(TimeoutError, "Call to 'connect' timed out.")
   else:
+    let res = getSockOptInt(socket.fd, SOL_SOCKET, SO_ERROR)
+    if res != 0:
+      raiseOSError(OSErrorCode(res))
     when defineSsl and not defined(nimdoc):
       if socket.isSSL:
         socket.fd.setBlocking(true)