Fix accept defect (#206)
* Fix accept() FutureDefect on cancellation. * Do not close pipe twice. * Check for retFuture state before changing it state.
This commit is contained in:
parent
15137f71c3
commit
14ebf269e9
|
@ -1032,9 +1032,10 @@ when defined(windows):
|
|||
var server = cast[StreamServer](ovl.data.udata)
|
||||
|
||||
server.apending = false
|
||||
if not(retFuture.finished()):
|
||||
if server.status in {ServerStatus.Stopped, ServerStatus.Closed}:
|
||||
server.asock.closeSocket()
|
||||
retFuture.fail(getServerUseClosedError())
|
||||
server.asock.closeSocket()
|
||||
server.clean()
|
||||
else:
|
||||
if ovl.data.errCode == OSErrorCode(-1):
|
||||
|
@ -1079,8 +1080,10 @@ when defined(windows):
|
|||
var server = cast[StreamServer](ovl.data.udata)
|
||||
|
||||
server.apending = false
|
||||
if not(retFuture.finished()):
|
||||
if server.status in {ServerStatus.Stopped, ServerStatus.Closed}:
|
||||
retFuture.fail(getServerUseClosedError())
|
||||
server.sock.closeHandle()
|
||||
server.clean()
|
||||
else:
|
||||
if ovl.data.errCode == OSErrorCode(-1):
|
||||
|
@ -1698,6 +1701,7 @@ else:
|
|||
saddr: Sockaddr_storage
|
||||
slen: SockLen
|
||||
|
||||
if not(retFuture.finished()):
|
||||
if server.status in {ServerStatus.Stopped, ServerStatus.Closed}:
|
||||
retFuture.fail(getServerUseClosedError())
|
||||
else:
|
||||
|
@ -1705,7 +1709,9 @@ else:
|
|||
let res = posix.accept(SocketHandle(server.sock),
|
||||
cast[ptr SockAddr](addr saddr), addr slen)
|
||||
if int(res) > 0:
|
||||
let sock = try: wrapAsyncSocket(res)
|
||||
let sock =
|
||||
try:
|
||||
wrapAsyncSocket(res)
|
||||
except CatchableError as exc:
|
||||
close(res)
|
||||
retFuture.fail(exc)
|
||||
|
@ -1718,7 +1724,8 @@ else:
|
|||
ntransp = newStreamSocketTransport(sock, server.bufferSize,
|
||||
transp)
|
||||
else:
|
||||
ntransp = newStreamSocketTransport(sock, server.bufferSize, nil)
|
||||
ntransp = newStreamSocketTransport(sock, server.bufferSize,
|
||||
nil)
|
||||
# Start tracking transport
|
||||
trackStream(ntransp)
|
||||
retFuture.complete(ntransp)
|
||||
|
@ -1737,6 +1744,7 @@ else:
|
|||
else:
|
||||
retFuture.fail(getTransportOsError(err))
|
||||
break
|
||||
|
||||
try:
|
||||
removeReader(server.sock)
|
||||
except IOSelectorsException as exc:
|
||||
|
|
Loading…
Reference in New Issue