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