From 1a2351f95fa1ddef0eb824426af355d079ed37cd Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Tue, 13 Feb 2018 10:08:37 +0000 Subject: Fixes #4995. (#7157) --- lib/pure/asyncnet.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/pure/asyncnet.nim') diff --git a/lib/pure/asyncnet.nim b/lib/pure/asyncnet.nim index bdbf47004..a75f9daac 100644 --- a/lib/pure/asyncnet.nim +++ b/lib/pure/asyncnet.nim @@ -163,8 +163,10 @@ proc newAsyncSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM, ## ## This procedure will also create a brand new file descriptor for ## this socket. - result = newAsyncSocket(newAsyncNativeSocket(domain, sockType, protocol), - domain, sockType, protocol, buffered) + let fd = createAsyncNativeSocket(domain, sockType, protocol) + if fd.SocketHandle == osInvalidSocket: + raiseOSError(osLastError()) + result = newAsyncSocket(fd, domain, sockType, protocol, buffered) proc newAsyncSocket*(domain, sockType, protocol: cint, buffered = true): AsyncSocket = @@ -172,8 +174,10 @@ proc newAsyncSocket*(domain, sockType, protocol: cint, ## ## This procedure will also create a brand new file descriptor for ## this socket. - result = newAsyncSocket(newAsyncNativeSocket(domain, sockType, protocol), - Domain(domain), SockType(sockType), + let fd = createAsyncNativeSocket(domain, sockType, protocol) + if fd.SocketHandle == osInvalidSocket: + raiseOSError(osLastError()) + result = newAsyncSocket(fd, Domain(domain), SockType(sockType), Protocol(protocol), buffered) when defineSsl: -- cgit 1.4.1-2-gfad0