Skip to content

Commit

Permalink
Hack to make readavailable block when no data is available.
Browse files Browse the repository at this point in the history
Fixes #16.
  • Loading branch information
malmaud committed Mar 1, 2016
1 parent e916d93 commit 378a62a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ssl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,14 @@ function Base.readbytes!(ctx::SSLContext, buf::Vector{UInt8}, nbytes::UInt)
end

function Base.readavailable(ctx::SSLContext)
n = nb_available(ctx)
return read(ctx, n)
# For unknown reasons, nb_available on SSLContext erroneously returns 0
# until `read` is called on the context. As a temporary hack, we read one
# byte from the SSL context to cause nb_available to be accurate.
# TODO: figure out and fix the root cause of this
b = IOBuffer()
write(b, read(ctx, 1))
write(b, read(ctx, nb_available(ctx)))
return takebuf_array(b)
end

function Base.eof(ctx::SSLContext)
Expand Down

1 comment on commit 378a62a

@samoconnor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @malmaud, could you please review attempted fix for this: #114

Please sign in to comment.