avoid triple lookup in `m.flushed` yamux table (#1045)
This commit is contained in:
parent
18e00a741b
commit
8cccd54125
|
@ -516,16 +516,20 @@ method handle*(m: Yamux) {.async.} =
|
||||||
await newStream.open()
|
await newStream.open()
|
||||||
asyncSpawn m.handleStream(newStream)
|
asyncSpawn m.handleStream(newStream)
|
||||||
elif header.streamId notin m.channels:
|
elif header.streamId notin m.channels:
|
||||||
if header.streamId notin m.flushed:
|
|
||||||
raise newException(YamuxError, "Unknown stream ID: " & $header.streamId)
|
|
||||||
elif header.msgType == Data:
|
|
||||||
# Flush the data
|
# Flush the data
|
||||||
m.flushed[header.streamId].dec(int(header.length))
|
m.flushed.withValue(header.streamId, flushed):
|
||||||
if m.flushed[header.streamId] < 0:
|
if header.msgType == Data:
|
||||||
raise newException(YamuxError, "Peer exhausted the recvWindow after reset")
|
flushed[].dec(int(header.length))
|
||||||
|
if flushed[] < 0:
|
||||||
|
raise newException(YamuxError,
|
||||||
|
"Peer exhausted the recvWindow after reset")
|
||||||
|
do:
|
||||||
|
raise newException(YamuxError,
|
||||||
|
"Unknown stream ID: " & $header.streamId)
|
||||||
if header.length > 0:
|
if header.length > 0:
|
||||||
var buffer = newSeqUninitialized[byte](header.length)
|
var buffer = newSeqUninitialized[byte](header.length)
|
||||||
await m.connection.readExactly(addr buffer[0], int(header.length))
|
await m.connection.readExactly(
|
||||||
|
addr buffer[0], int(header.length))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
let channel =
|
let channel =
|
||||||
|
|
Loading…
Reference in New Issue