close and cleanup connections
This commit is contained in:
parent
c6561b8851
commit
cd8961cfb9
|
@ -112,7 +112,6 @@ proc handle*(m: MultisteamSelect, conn: Connection) {.async, gcsafe.} =
|
|||
trace "handle: starting multistream handling"
|
||||
try:
|
||||
while not conn.closed:
|
||||
await sleepAsync(1.millis)
|
||||
var ms = cast[string]((await conn.readLp()))
|
||||
ms.removeSuffix("\n")
|
||||
|
||||
|
|
|
@ -125,7 +125,8 @@ method handle*(m: Mplex) {.async, gcsafe.} =
|
|||
trace "exception occurred", exception = exc.msg
|
||||
finally:
|
||||
trace "stopping mplex main loop"
|
||||
await m.connection.close()
|
||||
if not m.connection.closed():
|
||||
await m.connection.close()
|
||||
|
||||
proc newMplex*(conn: Connection,
|
||||
maxChanns: uint = MaxChannels): Mplex =
|
||||
|
@ -136,7 +137,8 @@ proc newMplex*(conn: Connection,
|
|||
result.local = initTable[uint, LPChannel]()
|
||||
|
||||
let m = result
|
||||
conn.closeEvent.wait().addCallback do (udata: pointer):
|
||||
conn.closeEvent.wait()
|
||||
.addCallback do (udata: pointer):
|
||||
trace "connection closed, cleaning up mplex"
|
||||
asyncCheck m.close()
|
||||
|
||||
|
|
|
@ -350,7 +350,8 @@ proc `|`*(s: BufferStream, target: BufferStream): BufferStream =
|
|||
method close*(s: BufferStream) {.async.} =
|
||||
## close the stream and clear the buffer
|
||||
for r in s.readReqs:
|
||||
r.cancel()
|
||||
if not(isNil(r)) and not(r.finished()):
|
||||
r.cancel()
|
||||
s.dataReadEvent.fire()
|
||||
s.readBuf.clear()
|
||||
s.closeEvent.fire()
|
||||
|
|
Loading…
Reference in New Issue