remote-curl: pass curl slot_results back through run_slot

Some callers may want to know more than just the integer error code we return. Let them optionally pass a slot_results struct to fill in (or NULL if they do not care). In either case we continue to return the integer code. We can also give probe_rpc the same treatment (since it builds directly on run_slot). Signed-off-by: Jeff King <peff@peff.net>

Jeff King committed Oct 31, 2013 at 02:36 UTC 3a347ed70727cdcb447040705b4128304c0244e3
1 file changed +13 -9
remote-curl.c
+13 -9
@@ -364,25 +364,29 @@ static size_t rpc_in(char *ptr, size_t eltsize,
364 return size;
365 }
366
367 -static int run_slot(struct active_request_slot *slot)
367 +static int run_slot(struct active_request_slot *slot,
368 + struct slot_results *results)
369 {
370 int err;
370 - struct slot_results results;
371 + struct slot_results results_buf;
372
372 - slot->results = &results;
373 + if (!results)
374 + results = &results_buf;
375 +
376 + slot->results = results;
377 slot->curl_result = curl_easy_perform(slot->curl);
378 finish_active_slot(slot);
379
376 - err = handle_curl_result(&results);
380 + err = handle_curl_result(results);
381 if (err != HTTP_OK && err != HTTP_REAUTH) {
382 error("RPC failed; result=%d, HTTP code = %ld",
379 - results.curl_result, results.http_code);
383 + results->curl_result, results->http_code);
384 }
385
386 return err;
387 }
388
385 -static int probe_rpc(struct rpc_state *rpc)
389 +static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
390 {
391 struct active_request_slot *slot;
392 struct curl_slist *headers = NULL;
@@ -404,7 +408,7 @@ static int probe_rpc(struct rpc_state *rpc)
408 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
409 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);
410
407 - err = run_slot(slot);
411 + err = run_slot(slot, results);
412
413 curl_slist_free_all(headers);
414 strbuf_release(&buf);
@@ -443,7 +447,7 @@ static int post_rpc(struct rpc_state *rpc)
447
448 if (large_request) {
449 do {
446 - err = probe_rpc(rpc);
450 + err = probe_rpc(rpc, NULL);
451 } while (err == HTTP_REAUTH);
452 if (err != HTTP_OK)
453 return -1;
@@ -542,7 +546,7 @@ retry:
546 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
547 curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
548
545 - err = run_slot(slot);
549 + err = run_slot(slot, NULL);
550 if (err == HTTP_REAUTH && !large_request)
551 goto retry;
552 if (err != HTTP_OK)