Skip to content

Commit 3be9f10

Browse files
vchuravyKristofferC
authored andcommitted
implement LibuvStream interface for BufferStream (#35545)
It is noted as a non-OS stream, but has also been a subtype of LibuvStream since forever. #32309 did not add the `readerror` field. (cherry picked from commit de04210)
1 parent fe43406 commit 3be9f10

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

base/stream.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ abstract type LibuvStream <: IO end
2323
# . +- Pipe
2424
# . +- Process (not exported)
2525
# . +- ProcessChain (not exported)
26-
# +- BufferStream
2726
# +- DevNull (not exported)
2827
# +- Filesystem.File
2928
# +- LibuvStream (not exported)
3029
# . +- PipeEndpoint (not exported)
3130
# . +- TCPSocket
3231
# . +- TTY (not exported)
3332
# . +- UDPSocket
33+
# . +- BufferStream (FIXME: 2.0)
3434
# +- IOBuffer = Base.GenericIOBuffer{Array{UInt8,1}}
3535
# +- IOStream
3636

@@ -1207,11 +1207,12 @@ end
12071207
mutable struct BufferStream <: LibuvStream
12081208
buffer::IOBuffer
12091209
cond::Threads.Condition
1210+
readerror::Any
12101211
is_open::Bool
12111212
buffer_writes::Bool
12121213
lock::ReentrantLock # advisory lock
12131214

1214-
BufferStream() = new(PipeBuffer(), Threads.Condition(), true, false, ReentrantLock())
1215+
BufferStream() = new(PipeBuffer(), Threads.Condition(), nothing, true, false, ReentrantLock())
12151216
end
12161217

12171218
isopen(s::BufferStream) = s.is_open

test/iobuffer.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ end
254254
@test close(bstream) === nothing
255255
@test eof(bstream)
256256
@test bytesavailable(bstream) == 0
257+
flag = Ref{Bool}(false)
258+
event = Base.Event()
259+
bstream = Base.BufferStream()
260+
task = @async begin
261+
notify(event)
262+
read(bstream, 16)
263+
flag[] = true
264+
end
265+
wait(event)
266+
write(bstream, rand(UInt8, 16))
267+
wait(task)
268+
@test flag[] == true
257269
end
258270

259271
@test flush(IOBuffer()) === nothing # should be a no-op

0 commit comments

Comments
 (0)