@@ -35,13 +35,22 @@ bio_clear_flags(bio::BIO) = bio_set_flags(bio, 0x00)
3535function on_bio_stream_read (bio:: BIO , out:: Ptr{Cchar} , outlen:: Cint )
3636 try
3737 bio_clear_flags (bio)
38- io = bio_get_data (bio):: TCPSocket
39- n = bytesavailable (io)
40- if n == 0
41- bio_set_read_retry (bio)
42- return Cint (0 )
38+ io = bio_get_data (bio)
39+ if io isa TCPSocket
40+ n = bytesavailable (io)
41+ if n == 0
42+ bio_set_read_retry (bio)
43+ return Cint (0 )
44+ end
45+ unsafe_read (io, out, min (UInt (n), outlen))
46+ else
47+ n = bytesavailable (io)
48+ if n == 0
49+ bio_set_read_retry (bio)
50+ return Cint (0 )
51+ end
52+ unsafe_read (io, out, min (UInt (n), outlen))
4353 end
44- unsafe_read (io, out, min (UInt (n), outlen))
4554 return Cint (min (n, outlen))
4655 catch e
4756 # we don't want to throw a Julia exception from a C callback
5160
5261function on_bio_stream_write (bio:: BIO , in:: Ptr{Cchar} , inlen:: Cint ):: Cint
5362 try
63+ <<<<<< < Updated upstream
5464 io = bio_get_data (bio):: TCPSocket
5565 written = unsafe_write (io, in, inlen)
66+ ====== =
67+ bio_clear_flags (bio)
68+ io = bio_get_data (bio)
69+ if io isa TCPSocket
70+ written = unsafe_write (io, in, inlen)
71+ else
72+ written = unsafe_write (io, in, inlen)
73+ end
74+ >>>>>> > Stashed changes
5675 return Cint (written)
5776 catch e
5877 # we don't want to throw a Julia exception from a C callback
@@ -373,12 +392,12 @@ end
373392"""
374393 SSLStream.
375394"""
376- mutable struct SSLStream <: IO
395+ mutable struct SSLStream{T} <: IO
377396 ssl:: SSL
378397 ssl_context:: SSLContext
379398 rbio:: BIO
380399 wbio:: BIO
381- io:: TCPSocket
400+ io:: T
382401 # used in `eof` where we want the call to `eof` on the underlying
383402 # socket and the SSL_peek call that processes bytes to be seen
384403 # as one "operation"
@@ -395,7 +414,7 @@ mutable struct SSLStream <: IO
395414 peekbytes:: Base.RefValue{Csize_t}
396415 closed:: Bool
397416
398- function SSLStream (ssl_context:: SSLContext , io:: TCPSocket )
417+ function SSLStream (ssl_context:: SSLContext , io:: T ) where {T <: IO }
399418 # Create a read and write BIOs.
400419 bio_read:: BIO = BIO (io; finalize= false )
401420 bio_write:: BIO = BIO (io; finalize= false )
@@ -404,7 +423,7 @@ mutable struct SSLStream <: IO
404423 end
405424end
406425
407- SSLStream (tcp:: TCPSocket ) = SSLStream (SSLContext (OpenSSL. TLSClientMethod ()), tcp)
426+ SSLStream (tcp:: IO ) = SSLStream (SSLContext (OpenSSL. TLSClientMethod ()), tcp)
408427
409428# backwards compat
410429Base. getproperty (ssl:: SSLStream , nm:: Symbol ) = nm === :bio_read_stream ? ssl : getfield (ssl, nm)
0 commit comments