bio: use splice! to reduce copy
parent
9df4760370
commit
0c68821bbc
|
@ -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) =
|
||||
|
|
|
@ -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…
Reference in New Issue