Skip to content

Commit

Permalink
remote-curl: pass curl slot_results back through run_slot
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Oct 31, 2013
1 parent 0972ccd commit 3a347ed
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions remote-curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,25 +364,29 @@ static size_t rpc_in(char *ptr, size_t eltsize,
return size;
}

static int run_slot(struct active_request_slot *slot)
static int run_slot(struct active_request_slot *slot,
struct slot_results *results)
{
int err;
struct slot_results results;
struct slot_results results_buf;

slot->results = &results;
if (!results)
results = &results_buf;

slot->results = results;
slot->curl_result = curl_easy_perform(slot->curl);
finish_active_slot(slot);

err = handle_curl_result(&results);
err = handle_curl_result(results);
if (err != HTTP_OK && err != HTTP_REAUTH) {
error("RPC failed; result=%d, HTTP code = %ld",
results.curl_result, results.http_code);
results->curl_result, results->http_code);
}

return err;
}

static int probe_rpc(struct rpc_state *rpc)
static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
{
struct active_request_slot *slot;
struct curl_slist *headers = NULL;
Expand All @@ -404,7 +408,7 @@ static int probe_rpc(struct rpc_state *rpc)
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);

err = run_slot(slot);
err = run_slot(slot, results);

curl_slist_free_all(headers);
strbuf_release(&buf);
Expand Down Expand Up @@ -443,7 +447,7 @@ static int post_rpc(struct rpc_state *rpc)

if (large_request) {
do {
err = probe_rpc(rpc);
err = probe_rpc(rpc, NULL);
} while (err == HTTP_REAUTH);
if (err != HTTP_OK)
return -1;
Expand Down Expand Up @@ -542,7 +546,7 @@ static int post_rpc(struct rpc_state *rpc)
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);

err = run_slot(slot);
err = run_slot(slot, NULL);
if (err == HTTP_REAUTH && !large_request)
goto retry;
if (err != HTTP_OK)
Expand Down

0 comments on commit 3a347ed

Please sign in to comment.