File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,12 +16,14 @@ type Stream* = ref object
1616 closed* : AsyncEvent # This is called when on_close callback is executed
1717 isEof* : bool # Received a FIN from remote
1818 toWrite* : seq [WriteTask ]
19+ lock: AsyncLock
1920
2021proc new * (T: typedesc [Stream ], quicStream: ptr lsquic_stream_t = nil ): T =
2122 let s = Stream (
2223 quicStream: quicStream,
2324 incoming: newAsyncQueue [seq [byte ]](),
2425 closed: newAsyncEvent (),
26+ lock: newAsyncLock (),
2527 )
2628 GC_ref (s) # Keep it pinned until stream_if.on_close is executed
2729 s
@@ -101,6 +103,13 @@ proc write*(
101103 if stream.closeWrite:
102104 raise newException (StreamError , " stream closed 3" )
103105
106+ await stream.lock.acquire ()
107+ defer :
108+ try :
109+ stream.lock.release ()
110+ except AsyncLockError :
111+ discard # should not happen - lock acquired directly above
112+
104113 let closedFut = stream.closed.wait ()
105114 let doneFut = Future [void ].Raising ([CancelledError , StreamError ]).init ()
106115 stream.toWrite.add (WriteTask (data: data, doneFut: doneFut))
You can’t perform that action at this time.
0 commit comments