Skip to content
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
16 changes: 8 additions & 8 deletions src/openssl/bio.cr
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,13 @@ struct OpenSSL::BIO
def self.read_ex(bio, buffer, len, readp)
count = len > Int32::MAX ? Int32::MAX : len.to_i
io = Box(IO).unbox(LibCrypto.BIO_get_data(bio))

# FIXME: why flush (write) before reading?!
io.flush

ret = io.read Slice.new(buffer, count)
readp.value = LibC::SizeT.new(ret)
1
end

def self.read(bio, buffer, len)
io = Box(IO).unbox(LibCrypto.BIO_get_data(bio))

# FIXME: why flush (write) before reading?!
io.flush

io.read(Slice.new(buffer, len)).to_i
end

Expand Down Expand Up @@ -92,6 +84,14 @@ struct OpenSSL::BIO
@boxed_io : Void*

def initialize(@io : IO)
if io.is_a?(IO::Buffered)
# Disable buffers of the underlying IO (e.g. TCP socket) so OpenSSL
# becomes responsible of what needs to be read/written on the wire;
# instead, buffers shall be on OpenSSL::SSL::Socket (for example).
io.sync = true
io.read_buffering = false
end

@bio = LibCrypto.BIO_new(CRYSTAL_BIO)

# We need to store a reference to the box because it's
Expand Down
7 changes: 0 additions & 7 deletions src/openssl/ssl/socket.cr
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ abstract class OpenSSL::SSL::Socket < IO
raise OpenSSL::Error.new("SSL_new")
end

# Since OpenSSL::SSL::Socket is buffered it makes no
# sense to wrap a IO::Buffered with buffering activated.
if io.is_a?(IO::Buffered)
io.sync = true
io.read_buffering = false
end

@bio = BIO.new(io)
LibSSL.ssl_set_bio(@ssl, @bio, @bio)
end
Expand Down
Loading