Fixed asyncio crash when sending buffered data after connection was terminated.
This commit is contained in:
parent
f5023ac544
commit
09b6b94509
1 changed files with 14 additions and 9 deletions
|
|
@ -213,6 +213,7 @@ proc asyncSockHandleRead(h: PObject) =
|
||||||
else:
|
else:
|
||||||
PAsyncSocket(h).handleAccept(PAsyncSocket(h))
|
PAsyncSocket(h).handleAccept(PAsyncSocket(h))
|
||||||
|
|
||||||
|
proc close*(sock: PAsyncSocket)
|
||||||
proc asyncSockHandleWrite(h: PObject) =
|
proc asyncSockHandleWrite(h: PObject) =
|
||||||
when defined(ssl):
|
when defined(ssl):
|
||||||
if PAsyncSocket(h).socket.isSSL and not
|
if PAsyncSocket(h).socket.isSSL and not
|
||||||
|
|
@ -230,6 +231,7 @@ proc asyncSockHandleWrite(h: PObject) =
|
||||||
else:
|
else:
|
||||||
if PAsyncSocket(h).sendBuffer != "":
|
if PAsyncSocket(h).sendBuffer != "":
|
||||||
let sock = PAsyncSocket(h)
|
let sock = PAsyncSocket(h)
|
||||||
|
try:
|
||||||
let bytesSent = sock.socket.sendAsync(sock.sendBuffer)
|
let bytesSent = sock.socket.sendAsync(sock.sendBuffer)
|
||||||
assert bytesSent > 0
|
assert bytesSent > 0
|
||||||
if bytesSent != sock.sendBuffer.len:
|
if bytesSent != sock.sendBuffer.len:
|
||||||
|
|
@ -239,6 +241,9 @@ proc asyncSockHandleWrite(h: PObject) =
|
||||||
|
|
||||||
if PAsyncSocket(h).handleWrite != nil:
|
if PAsyncSocket(h).handleWrite != nil:
|
||||||
PAsyncSocket(h).handleWrite(PAsyncSocket(h))
|
PAsyncSocket(h).handleWrite(PAsyncSocket(h))
|
||||||
|
except EOS, ESSL:
|
||||||
|
# Most likely the socket closed before the full buffer could be sent to it.
|
||||||
|
sock.close() # TODO: Provide a handleError for users?
|
||||||
else:
|
else:
|
||||||
if PAsyncSocket(h).handleWrite != nil:
|
if PAsyncSocket(h).handleWrite != nil:
|
||||||
PAsyncSocket(h).handleWrite(PAsyncSocket(h))
|
PAsyncSocket(h).handleWrite(PAsyncSocket(h))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue