Skip to content

Commit 73a0da4

Browse files
authored
Add type asserts to bio_get_data (#11)
* Add type asserts to `bio_get_data` * Reduce the number of heap allocated ints in on_bio_stream_read * `on_bio_stream_write` can use `IOBuffer`
1 parent f733e49 commit 73a0da4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/ssl.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,14 @@ bio_clear_flags(bio::BIO) = bio_set_flags(bio, 0x00)
3535
function on_bio_stream_read(bio::BIO, out::Ptr{Cchar}, outlen::Cint)
3636
try
3737
bio_clear_flags(bio)
38-
io = bio_get_data(bio)
38+
io = bio_get_data(bio)::TCPSocket
3939
n = bytesavailable(io)
4040
if n == 0
4141
bio_set_read_retry(bio)
4242
return Cint(0)
4343
end
44-
outlen = min(outlen, n)
45-
unsafe_read(io, out, outlen)
46-
return Cint(outlen)
44+
unsafe_read(io, out, min(UInt(n), outlen))
45+
return Cint(min(n, outlen))
4746
catch e
4847
# we don't want to throw a Julia exception from a C callback
4948
return Cint(0)
@@ -639,7 +638,7 @@ function Base.close(ssl::SSLStream, shutdown::Bool=true)
639638
end
640639
finalize(ssl.ssl)
641640
end
642-
return
641+
return
643642
end
644643

645644
"""

0 commit comments

Comments
 (0)