move stram close to a better location
This commit is contained in:
parent
daef00fc7b
commit
abc12d0fb5
|
@ -49,7 +49,10 @@ proc newStreamInternal*(m: Mplex,
|
|||
lazy: bool = false):
|
||||
Future[LPChannel] {.async, gcsafe.} =
|
||||
## create new channel/stream
|
||||
let id = if initiator: m.currentId.inc(); m.currentId else: chanId
|
||||
let id = if initiator:
|
||||
m.currentId.inc(); m.currentId
|
||||
else: chanId
|
||||
|
||||
trace "creating new channel", channelId = id,
|
||||
initiator = initiator,
|
||||
name = name,
|
||||
|
@ -99,13 +102,8 @@ method handle*(m: Mplex) {.async, gcsafe.} =
|
|||
|
||||
var fut = newFuture[void]()
|
||||
proc handler() {.async.} =
|
||||
try:
|
||||
try:
|
||||
await m.streamHandler(stream)
|
||||
trace "streamhandler ended", oid = stream.oid
|
||||
finally:
|
||||
if not(stream.closed):
|
||||
await stream.close()
|
||||
except CatchableError as exc:
|
||||
trace "exception in stream handler", exc = exc.msg
|
||||
finally:
|
||||
|
|
|
@ -425,8 +425,15 @@ proc newSwitch*(peerInfo: PeerInfo,
|
|||
|
||||
let s = result # can't capture result
|
||||
result.streamHandler = proc(stream: Connection) {.async, gcsafe.} =
|
||||
try:
|
||||
trace "handling connection for", peerInfo = $stream.peerInfo
|
||||
try:
|
||||
await s.ms.handle(stream) # handle incoming connection
|
||||
finally:
|
||||
if not(stream.closed):
|
||||
await stream.close()
|
||||
except CatchableError as exc:
|
||||
trace "excepton in stream handler", exc = exc.msg
|
||||
|
||||
result.mount(identity)
|
||||
for key, val in muxers:
|
||||
|
|
Loading…
Reference in New Issue