From 378a62a6103ef6676bbd53a62691b68da89b16fb Mon Sep 17 00:00:00 2001 From: Jon Malmaud Date: Tue, 1 Mar 2016 16:54:00 -0500 Subject: [PATCH] Hack to make readavailable block when no data is available. Fixes #16. --- src/ssl.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ssl.jl b/src/ssl.jl index 16fa5b6..b00d3dc 100644 --- a/src/ssl.jl +++ b/src/ssl.jl @@ -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)