Skip to content

Commit 0e3ec4f

Browse files
authored
Avoid one more Ref allocation (#12)
1 parent 73a0da4 commit 0e3ec4f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ssl.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ mutable struct SSLStream <: IO
398398
wbio::BIO
399399
io::TCPSocket
400400
lock::ReentrantLock
401+
readbytes::Base.RefValue{Csize_t}
401402
@static if VERSION < v"1.7"
402403
close_notify_received::Threads.Atomic{Bool}
403404
closed::Threads.Atomic{Bool}
@@ -413,9 +414,9 @@ end
413414
ssl = SSL(ssl_context, bio_read, bio_write)
414415

415416
@static if VERSION < v"1.7"
416-
return new(ssl, ssl_context, bio_read, bio_write, io, ReentrantLock(), Threads.Atomic{Bool}(false), Threads.Atomic{Bool}(false))
417+
return new(ssl, ssl_context, bio_read, bio_write, io, ReentrantLock(), Ref{Csize_t}(0), Threads.Atomic{Bool}(false), Threads.Atomic{Bool}(false))
417418
else
418-
return new(ssl, ssl_context, bio_read, bio_write, io, ReentrantLock(), false, false)
419+
return new(ssl, ssl_context, bio_read, bio_write, io, ReentrantLock(), Ref{Csize_t}(0), false, false)
419420
end
420421
end
421422
end
@@ -534,7 +535,7 @@ function Base.unsafe_read(ssl::SSLStream, buf::Ptr{UInt8}, nbytes::UInt)
534535
nread = 0
535536
while nread < nbytes
536537
(!isopen(ssl) || eof(ssl)) && throw(EOFError())
537-
readbytes = Ref{Csize_t}()
538+
readbytes = ssl.readbytes
538539
@geterror ccall(
539540
(:SSL_read_ex, libssl),
540541
Cint,

0 commit comments

Comments
 (0)