Skip to content

Commit

Permalink
implement LibuvStream interface for BufferStream (#35545)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
vchuravy authored and KristofferC committed May 10, 2020
1 parent fe43406 commit 3be9f10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ abstract type LibuvStream <: IO end
# . +- Pipe
# . +- Process (not exported)
# . +- ProcessChain (not exported)
# +- BufferStream
# +- DevNull (not exported)
# +- Filesystem.File
# +- LibuvStream (not exported)
# . +- PipeEndpoint (not exported)
# . +- TCPSocket
# . +- TTY (not exported)
# . +- UDPSocket
# . +- BufferStream (FIXME: 2.0)
# +- IOBuffer = Base.GenericIOBuffer{Array{UInt8,1}}
# +- IOStream

Expand Down Expand Up @@ -1207,11 +1207,12 @@ end
mutable struct BufferStream <: LibuvStream
buffer::IOBuffer
cond::Threads.Condition
readerror::Any
is_open::Bool
buffer_writes::Bool
lock::ReentrantLock # advisory lock

BufferStream() = new(PipeBuffer(), Threads.Condition(), true, false, ReentrantLock())
BufferStream() = new(PipeBuffer(), Threads.Condition(), nothing, true, false, ReentrantLock())
end

isopen(s::BufferStream) = s.is_open
Expand Down
12 changes: 12 additions & 0 deletions test/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ end
@test close(bstream) === nothing
@test eof(bstream)
@test bytesavailable(bstream) == 0
flag = Ref{Bool}(false)
event = Base.Event()
bstream = Base.BufferStream()
task = @async begin
notify(event)
read(bstream, 16)
flag[] = true
end
wait(event)
write(bstream, rand(UInt8, 16))
wait(task)
@test flag[] == true
end

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

0 comments on commit 3be9f10

Please sign in to comment.