mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-01-10 21:16:30 +00:00
chore(yamux): change closedRemotely from Future into AsyncEvent (#1133)
This commit is contained in:
parent
0f27f896ab
commit
d1d53ff369
@ -155,7 +155,7 @@ type
|
|||||||
recvQueue: seq[byte]
|
recvQueue: seq[byte]
|
||||||
isReset: bool
|
isReset: bool
|
||||||
remoteReset: bool
|
remoteReset: bool
|
||||||
closedRemotely: Future[void].Raising([])
|
closedRemotely: AsyncEvent
|
||||||
closedLocally: bool
|
closedLocally: bool
|
||||||
receivedData: AsyncEvent
|
receivedData: AsyncEvent
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ proc `$`(channel: YamuxChannel): string =
|
|||||||
result = if channel.conn.dir == Out: "=> " else: "<= "
|
result = if channel.conn.dir == Out: "=> " else: "<= "
|
||||||
result &= $channel.id
|
result &= $channel.id
|
||||||
var s: seq[string] = @[]
|
var s: seq[string] = @[]
|
||||||
if channel.closedRemotely.completed():
|
if channel.closedRemotely.isSet():
|
||||||
s.add("ClosedRemotely")
|
s.add("ClosedRemotely")
|
||||||
if channel.closedLocally:
|
if channel.closedLocally:
|
||||||
s.add("ClosedLocally")
|
s.add("ClosedLocally")
|
||||||
@ -198,12 +198,12 @@ proc lengthSendQueueWithLimit(channel: YamuxChannel): int =
|
|||||||
|
|
||||||
proc actuallyClose(channel: YamuxChannel) {.async: (raises: []).} =
|
proc actuallyClose(channel: YamuxChannel) {.async: (raises: []).} =
|
||||||
if channel.closedLocally and channel.sendQueue.len == 0 and
|
if channel.closedLocally and channel.sendQueue.len == 0 and
|
||||||
channel.closedRemotely.completed():
|
channel.closedRemotely.isSet():
|
||||||
await procCall Connection(channel).closeImpl()
|
await procCall Connection(channel).closeImpl()
|
||||||
|
|
||||||
proc remoteClosed(channel: YamuxChannel) {.async: (raises: []).} =
|
proc remoteClosed(channel: YamuxChannel) {.async: (raises: []).} =
|
||||||
if not channel.closedRemotely.completed():
|
if not channel.closedRemotely.isSet():
|
||||||
channel.closedRemotely.complete()
|
channel.closedRemotely.fire()
|
||||||
await channel.actuallyClose()
|
await channel.actuallyClose()
|
||||||
|
|
||||||
method closeImpl*(channel: YamuxChannel) {.async: (raises: []).} =
|
method closeImpl*(channel: YamuxChannel) {.async: (raises: []).} =
|
||||||
@ -239,7 +239,7 @@ proc reset(channel: YamuxChannel, isLocal: bool = false) {.async: (raises: []).}
|
|||||||
except CancelledError, LPStreamError:
|
except CancelledError, LPStreamError:
|
||||||
discard
|
discard
|
||||||
await channel.close()
|
await channel.close()
|
||||||
if not channel.closedRemotely.completed():
|
if not channel.closedRemotely.isSet():
|
||||||
await channel.remoteClosed()
|
await channel.remoteClosed()
|
||||||
channel.receivedData.fire()
|
channel.receivedData.fire()
|
||||||
if not isLocal:
|
if not isLocal:
|
||||||
@ -280,10 +280,10 @@ method readOnce*(
|
|||||||
if channel.recvQueue.len == 0:
|
if channel.recvQueue.len == 0:
|
||||||
channel.receivedData.clear()
|
channel.receivedData.clear()
|
||||||
try: # https://github.com/status-im/nim-chronos/issues/516
|
try: # https://github.com/status-im/nim-chronos/issues/516
|
||||||
discard await race(channel.closedRemotely, channel.receivedData.wait())
|
discard await race(channel.closedRemotely.wait(), channel.receivedData.wait())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raiseAssert("Futures list is not empty")
|
raiseAssert("Futures list is not empty")
|
||||||
if channel.closedRemotely.completed() and channel.recvQueue.len == 0:
|
if channel.closedRemotely.isSet() and channel.recvQueue.len == 0:
|
||||||
channel.isEof = true
|
channel.isEof = true
|
||||||
return
|
return
|
||||||
0 # we return 0 to indicate that the channel is closed for reading from now on
|
0 # we return 0 to indicate that the channel is closed for reading from now on
|
||||||
@ -460,9 +460,6 @@ proc createStream(
|
|||||||
# that the initial recvWindow is 256k.
|
# that the initial recvWindow is 256k.
|
||||||
# To solve this contradiction, no updateWindow will be sent until
|
# To solve this contradiction, no updateWindow will be sent until
|
||||||
# recvWindow is less than maxRecvWindow
|
# recvWindow is less than maxRecvWindow
|
||||||
proc newClosedRemotelyFut(): Future[void] {.async: (raises: [], raw: true).} =
|
|
||||||
newFuture[void]()
|
|
||||||
|
|
||||||
var stream = YamuxChannel(
|
var stream = YamuxChannel(
|
||||||
id: id,
|
id: id,
|
||||||
maxRecvWindow: recvWindow,
|
maxRecvWindow: recvWindow,
|
||||||
@ -473,7 +470,7 @@ proc createStream(
|
|||||||
isSrc: isSrc,
|
isSrc: isSrc,
|
||||||
conn: m.connection,
|
conn: m.connection,
|
||||||
receivedData: newAsyncEvent(),
|
receivedData: newAsyncEvent(),
|
||||||
closedRemotely: newClosedRemotelyFut(),
|
closedRemotely: newAsyncEvent(),
|
||||||
)
|
)
|
||||||
stream.objName = "YamuxStream"
|
stream.objName = "YamuxStream"
|
||||||
if isSrc:
|
if isSrc:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user