Skip to content

Commit 57af2ea

Browse files
committed
test
1 parent e80602d commit 57af2ea

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lsquic/stream.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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

2021
proc 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))

0 commit comments

Comments
 (0)