Skip to content

Commit 856f104

Browse files
combine easy buffers (errbuf & readbuf)
1 parent a7ea0cb commit 856f104

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/Curl/Easy.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ mutable struct Easy
88
req_hdrs :: Ptr{curl_slist_t}
99
res_hdrs :: Vector{String}
1010
code :: CURLcode
11-
errbuf :: Vector{UInt8}
12-
readbuf :: Vector{UInt8}
11+
buffer :: Vector{UInt8}
1312
end
1413

1514
function Easy(
@@ -28,7 +27,6 @@ function Easy(
2827
String[],
2928
typemax(CURLcode),
3029
zeros(UInt8, CURL_ERROR_SIZE),
31-
zeros(UInt8, 0),
3230
)
3331
finalizer(done!, easy)
3432
add_callbacks(easy)
@@ -279,9 +277,9 @@ end
279277

280278
function get_curl_errstr(easy::Easy)
281279
easy.code == Curl.CURLE_OK && return ""
282-
errstr = easy.errbuf[1] == 0 ?
280+
errstr = easy.buffer[1] == 0 ?
283281
unsafe_string(Curl.curl_easy_strerror(easy.code)) :
284-
GC.@preserve easy unsafe_string(pointer(easy.errbuf))
282+
GC.@preserve easy unsafe_string(pointer(easy.buffer))
285283
return chomp(errstr)
286284
end
287285

@@ -308,8 +306,8 @@ function read_callback(
308306
)::Csize_t
309307
easy = unsafe_pointer_to_objref(easy_p)::Easy
310308
eof(easy.input) && return 0
311-
n = readbytes!(easy.input, easy.readbuf, size*count)
312-
ccall(:memcpy, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}, Csize_t), data, easy.readbuf, n)
309+
n = readbytes!(easy.input, easy.buffer, size*count)
310+
ccall(:memcpy, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}, Csize_t), data, easy.buffer, n)
313311
return n
314312
end
315313

@@ -363,8 +361,8 @@ function add_callbacks(easy::Easy)
363361
setopt(easy, CURLOPT_PRIVATE, easy_p)
364362

365363
# pointer to error buffer
366-
errbuf_p = pointer(easy.errbuf)
367-
setopt(easy, CURLOPT_ERRORBUFFER, errbuf_p)
364+
buffer_p = pointer(easy.buffer)
365+
setopt(easy, CURLOPT_ERRORBUFFER, buffer_p)
368366

369367
# set header callback
370368
header_cb = @cfunction(header_callback,

0 commit comments

Comments
 (0)