Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement LibuvStream interface for BufferStream #35545

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1202,11 +1202,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