Browse Source

bio: use splice! to reduce copy

master
nixo 2 years ago
parent
commit
0c68821bbc
  1. 8
      src/bio.jl
  2. 4
      src/flow_control.jl

8
src/bio.jl

@ -31,10 +31,12 @@ function bio_write!(client::SSLClient, data)
end
function bio_read(client::SSLClient)
buff = Vector{UInt8}(undef, 64)
buff_length = 64
buff = Vector{UInt8}(undef, buff_length)
n = ccall((:BIO_read, libssl), Cint, (Ptr{Cvoid},Ptr{Cvoid},Cint),
client.wbio, buff, length(buff))
n, n > 0 ? buff[1:n] : buff
client.wbio, buff, buff_length)
n > 0 && splice!(buff, (n+1):buff_length)
n, buff
end
bio_test_flags(bio, flags) =

4
src/flow_control.jl

@ -37,7 +37,7 @@ function do_encrypt(client)
status = ccall((:SSL_get_error, libssl), SSL_ERRORS, (Ptr{Cvoid}, Cint),
client.ssl, n)
if n > 0
client.encrypt_buf = client.encrypt_buf[(n+1):end]
splice!(client.encrypt_buf, 1:n)
while true
(n, buf) = bio_read(client)
if n > 0
@ -121,7 +121,7 @@ function do_sock_write(client::SSLClient)
n = write(client.sock, client.write_buf)
# println("Written to the client: $n")
if n > 0
client.write_buf = client.write_buf[(n+1):end]
splice!(client.write_buf, 1:n)
return 0
else
return -1

Loading…
Cancel
Save