remote-curl: define struct for CURLOPT_WRITEFUNCTION

In order to pass more values for rpc_in, define a struct and pass it as
an additional value.

Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Masaya Suzuki 2019-01-10 11:33:48 -08:00 committed by Junio C Hamano
parent e6cf87b12d
commit cf2fb92b00

View File

@ -545,14 +545,22 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
}
#endif
struct rpc_in_data {
struct rpc_state *rpc;
};
/*
* A callback for CURLOPT_WRITEFUNCTION. The return value is the bytes consumed
* from ptr.
*/
static size_t rpc_in(char *ptr, size_t eltsize,
size_t nmemb, void *buffer_)
{
size_t size = eltsize * nmemb;
struct rpc_state *rpc = buffer_;
struct rpc_in_data *data = buffer_;
if (size)
rpc->any_written = 1;
write_or_die(rpc->in, ptr, size);
data->rpc->any_written = 1;
write_or_die(data->rpc->in, ptr, size);
return size;
}
@ -632,6 +640,7 @@ static int post_rpc(struct rpc_state *rpc)
size_t gzip_size = 0;
int err, large_request = 0;
int needs_100_continue = 0;
struct rpc_in_data rpc_in_data;
/* Try to load the entire request, if we can fit it into the
* allocated buffer space we can use HTTP/1.0 and avoid the
@ -764,7 +773,8 @@ retry:
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
rpc_in_data.rpc = rpc;
curl_easy_setopt(slot->curl, CURLOPT_FILE, &rpc_in_data);
rpc->any_written = 0;