diff --git a/src/OpenSSL.jl b/src/OpenSSL.jl index 3d66a9e..ccf2bbd 100644 --- a/src/OpenSSL.jl +++ b/src/OpenSSL.jl @@ -40,8 +40,9 @@ write(c::SSLClient, s::String) = write(c, Vector{UInt8}(s)) import Base.close function close(client::SSLClient) + closed = do_ssl_shutdown(client) + @show closed close(client.sock) - shutdown(client) free(client) end diff --git a/src/flow_control.jl b/src/flow_control.jl index 6ee239c..3c8bbdf 100644 --- a/src/flow_control.jl +++ b/src/flow_control.jl @@ -128,3 +128,30 @@ function do_sock_write(client::SSLClient) return -1 end end + +function do_ssl_shutdown(client) + n = shutdown(client) + status = ssl_status(client, n) + # Special case, do the shutdown again + if n == 0 + n = shutdown(client) + @show status = ssl_status(client, n) + end + if status in (SSL_WANT_READ, SSL_WANT_WRITE) + @info "READING" + while true + (n, buf) = bio_read(client) + println("bio_read: $(n)") + if n > 0 + queue_encrypted_bytes(client, buf) + elseif !bio_should_retry(client.wbio) + return -1 + else + break + end + end + end + @show ssl_status(client, shutdown(client)) + # println("End of ssl handshake") + return status +end