mirror of https://github.com/vacp2p/nim-libp2p.git
use loop on closed flag
This commit is contained in:
parent
402067ceae
commit
f24c866a30
|
@ -64,7 +64,7 @@ proc handle*(m: MultisteamSelect, conn: Connection) {.async.} =
|
||||||
if not (await m.select(conn)):
|
if not (await m.select(conn)):
|
||||||
return
|
return
|
||||||
|
|
||||||
block handleLoop:
|
while not conn.closed:
|
||||||
var ms = cast[string](await conn.readLp())
|
var ms = cast[string](await conn.readLp())
|
||||||
ms.removeSuffix("\n")
|
ms.removeSuffix("\n")
|
||||||
if ms.len() <= 0:
|
if ms.len() <= 0:
|
||||||
|
@ -73,16 +73,14 @@ proc handle*(m: MultisteamSelect, conn: Connection) {.async.} =
|
||||||
case ms:
|
case ms:
|
||||||
of "ls":
|
of "ls":
|
||||||
for h in m.handlers:
|
for h in m.handlers:
|
||||||
await conn.writeLp(h.proto)
|
await conn.writeLp(h.proto & "\n")
|
||||||
break handleLoop
|
|
||||||
else:
|
else:
|
||||||
for h in m.handlers:
|
for h in m.handlers:
|
||||||
if (not isNil(h.match) and h.match(ms)) or ms == h.proto:
|
if (not isNil(h.match) and h.match(ms)) or ms == h.proto:
|
||||||
await h.handler(conn, ms)
|
await h.handler(conn, ms)
|
||||||
break
|
return
|
||||||
else:
|
else:
|
||||||
await conn.write(Na)
|
await conn.write(Na)
|
||||||
break handleLoop
|
|
||||||
|
|
||||||
proc addHandler*(m: MultisteamSelect,
|
proc addHandler*(m: MultisteamSelect,
|
||||||
proto: string,
|
proto: string,
|
||||||
|
|
Loading…
Reference in New Issue