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>
Masaya Suzuki committed
Jan 10, 2019 at 11:33 UTC
cf2fb92b00df0594aac2176b524db45b62795a38
1 file changed
+14
-4
remote-curl.c
+14
-4
@@ -545,14 +545,22 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
545
}
546
#endif
547
548
+struct rpc_in_data {
549
+ struct rpc_state *rpc;
550
+};
551
+
552
+/*
553
+ * A callback for CURLOPT_WRITEFUNCTION. The return value is the bytes consumed
554
+ * from ptr.
555
+ */
556
static size_t rpc_in(char *ptr, size_t eltsize,
557
size_t nmemb, void *buffer_)
558
{
559
size_t size = eltsize * nmemb;
552
- struct rpc_state *rpc = buffer_;
560
+ struct rpc_in_data *data = buffer_;
561
if (size)
554
- rpc->any_written = 1;
555
- write_or_die(rpc->in, ptr, size);
562
+ data->rpc->any_written = 1;
563
+ write_or_die(data->rpc->in, ptr, size);
564
return size;
565
}
566
@@ -632,6 +640,7 @@ static int post_rpc(struct rpc_state *rpc)
640
size_t gzip_size = 0;
641
int err, large_request = 0;
642
int needs_100_continue = 0;
643
+ struct rpc_in_data rpc_in_data;
644
645
/* Try to load the entire request, if we can fit it into the
646
* allocated buffer space we can use HTTP/1.0 and avoid the
@@ -764,7 +773,8 @@ retry:
773
774
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
775
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
767
- curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
776
+ rpc_in_data.rpc = rpc;
777
+ curl_easy_setopt(slot->curl, CURLOPT_FILE, &rpc_in_data);
778
779
780
rpc->any_written = 0;