From 0c68821bbccfa070de498727c952e172e1709226 Mon Sep 17 00:00:00 2001 From: nixo Date: Mon, 26 Oct 2020 21:08:22 +0100 Subject: [PATCH] bio: use splice! to reduce copy --- src/bio.jl | 8 +++++--- src/flow_control.jl | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/bio.jl b/src/bio.jl index 68696cd..4b0292b 100644 --- a/src/bio.jl +++ b/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) = diff --git a/src/flow_control.jl b/src/flow_control.jl index 0a8db3e..2cc8c13 100644 --- a/src/flow_control.jl +++ b/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