HTTP slot reuse fixes
Incorporate into http-push a fix related to accessing slot results after the slot was reused, and fix a case in run_active_slot where a finished slot wasn't detected if the slot was reused. Signed-off-by: Junio C Hamano <junkio@cox.net>
Nick Hengeveld committed
Mar 10, 2006 at 20:18 UTC
baa7b67d091acf4c666e79e386712bd5ea79326c
3 files changed
+49
-20
http-push.c
+41
-19
@@ -302,6 +302,7 @@ static void start_move(struct transfer_request *request)
302
static int refresh_lock(struct remote_lock *check_lock)
303
{
304
struct active_request_slot *slot;
305
+ struct slot_results results;
306
char *if_header;
307
char timeout_header[25];
308
struct curl_slist *dav_headers = NULL;
@@ -329,6 +330,7 @@ static int refresh_lock(struct remote_lock *check_lock)
330
dav_headers = curl_slist_append(dav_headers, timeout_header);
331
332
slot = get_active_slot();
333
+ slot->results = &results;
334
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
335
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
336
curl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);
@@ -337,8 +339,8 @@ static int refresh_lock(struct remote_lock *check_lock)
339
340
if (start_active_slot(slot)) {
341
run_active_slot(slot);
340
- if (slot->curl_result != CURLE_OK) {
341
- fprintf(stderr, "Got HTTP error %ld\n", slot->http_code);
342
+ if (results.curl_result != CURLE_OK) {
343
+ fprintf(stderr, "Got HTTP error %ld\n", results.http_code);
344
lock->active = 0;
345
} else {
346
lock->active = 1;
@@ -509,16 +511,18 @@ static int fetch_index(unsigned char *sha1)
511
512
FILE *indexfile;
513
struct active_request_slot *slot;
514
+ struct slot_results results;
515
516
/* Don't use the index if the pack isn't there */
517
url = xmalloc(strlen(remote->url) + 65);
518
sprintf(url, "%s/objects/pack/pack-%s.pack", remote->url, hex);
519
slot = get_active_slot();
520
+ slot->results = &results;
521
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
522
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);
523
if (start_active_slot(slot)) {
524
run_active_slot(slot);
521
- if (slot->curl_result != CURLE_OK) {
525
+ if (results.curl_result != CURLE_OK) {
526
free(url);
527
return error("Unable to verify pack %s is available",
528
hex);
@@ -543,6 +547,7 @@ static int fetch_index(unsigned char *sha1)
547
filename);
548
549
slot = get_active_slot();
550
+ slot->results = &results;
551
curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
552
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
553
curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
@@ -566,7 +571,7 @@ static int fetch_index(unsigned char *sha1)
571
572
if (start_active_slot(slot)) {
573
run_active_slot(slot);
569
- if (slot->curl_result != CURLE_OK) {
574
+ if (results.curl_result != CURLE_OK) {
575
free(url);
576
fclose(indexfile);
577
return error("Unable to get pack index %s\n%s", url,
@@ -606,6 +611,7 @@ static int fetch_indices(void)
611
int i = 0;
612
613
struct active_request_slot *slot;
614
+ struct slot_results results;
615
616
data = xmalloc(4096);
617
memset(data, 0, 4096);
@@ -620,16 +626,17 @@ static int fetch_indices(void)
626
sprintf(url, "%s/objects/info/packs", remote->url);
627
628
slot = get_active_slot();
629
+ slot->results = &results;
630
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
631
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
632
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
633
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
634
if (start_active_slot(slot)) {
635
run_active_slot(slot);
629
- if (slot->curl_result != CURLE_OK) {
636
+ if (results.curl_result != CURLE_OK) {
637
free(buffer.buffer);
638
free(url);
632
- if (slot->http_code == 404)
639
+ if (results.http_code == 404)
640
return 0;
641
else
642
return error("%s", curl_errorstr);
@@ -716,20 +723,22 @@ int fetch_ref(char *ref, unsigned char *sha1)
723
struct buffer buffer;
724
char *base = remote->url;
725
struct active_request_slot *slot;
726
+ struct slot_results results;
727
buffer.size = 41;
728
buffer.posn = 0;
729
buffer.buffer = hex;
730
hex[41] = '\0';
723
-
731
+
732
url = quote_ref_url(base, ref);
733
slot = get_active_slot();
734
+ slot->results = &results;
735
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
736
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
737
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
738
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
739
if (start_active_slot(slot)) {
740
run_active_slot(slot);
732
- if (slot->curl_result != CURLE_OK)
741
+ if (results.curl_result != CURLE_OK)
742
return error("Couldn't get %s for %s\n%s",
743
url, ref, curl_errorstr);
744
} else {
@@ -913,6 +922,7 @@ xml_cdata(void *userData, const XML_Char *s, int len)
922
static struct remote_lock *lock_remote(char *path, long timeout)
923
{
924
struct active_request_slot *slot;
925
+ struct slot_results results;
926
struct buffer out_buffer;
927
struct buffer in_buffer;
928
char *out_data;
@@ -946,14 +956,15 @@ static struct remote_lock *lock_remote(char *path, long timeout)
956
while (ep) {
957
*ep = 0;
958
slot = get_active_slot();
959
+ slot->results = &results;
960
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
961
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
962
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_MKCOL);
963
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
964
if (start_active_slot(slot)) {
965
run_active_slot(slot);
955
- if (slot->curl_result != CURLE_OK &&
956
- slot->http_code != 405) {
966
+ if (results.curl_result != CURLE_OK &&
967
+ results.http_code != 405) {
968
fprintf(stderr,
969
"Unable to create branch path %s\n",
970
url);
@@ -985,6 +996,7 @@ static struct remote_lock *lock_remote(char *path, long timeout)
996
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
997
998
slot = get_active_slot();
999
+ slot->results = &results;
1000
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
1001
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
1002
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
@@ -1003,7 +1015,7 @@ static struct remote_lock *lock_remote(char *path, long timeout)
1015
1016
if (start_active_slot(slot)) {
1017
run_active_slot(slot);
1006
- if (slot->curl_result == CURLE_OK) {
1018
+ if (results.curl_result == CURLE_OK) {
1019
ctx.name = xcalloc(10, 1);
1020
ctx.len = 0;
1021
ctx.cdata = NULL;
@@ -1053,6 +1065,7 @@ static struct remote_lock *lock_remote(char *path, long timeout)
1065
static int unlock_remote(struct remote_lock *lock)
1066
{
1067
struct active_request_slot *slot;
1068
+ struct slot_results results;
1069
char *lock_token_header;
1070
struct curl_slist *dav_headers = NULL;
1071
int rc = 0;
@@ -1063,6 +1076,7 @@ static int unlock_remote(struct remote_lock *lock)
1076
dav_headers = curl_slist_append(dav_headers, lock_token_header);
1077
1078
slot = get_active_slot();
1079
+ slot->results = &results;
1080
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
1081
curl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);
1082
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_UNLOCK);
@@ -1070,11 +1084,11 @@ static int unlock_remote(struct remote_lock *lock)
1084
1085
if (start_active_slot(slot)) {
1086
run_active_slot(slot);
1073
- if (slot->curl_result == CURLE_OK)
1087
+ if (results.curl_result == CURLE_OK)
1088
rc = 1;
1089
else
1090
fprintf(stderr, "Got HTTP error %ld\n",
1077
- slot->http_code);
1091
+ results.http_code);
1092
} else {
1093
fprintf(stderr, "Unable to start request\n");
1094
}
@@ -1091,6 +1105,7 @@ static void crawl_remote_refs(char *path)
1105
{
1106
char *url;
1107
struct active_request_slot *slot;
1108
+ struct slot_results results;
1109
struct buffer in_buffer;
1110
struct buffer out_buffer;
1111
char *in_data;
@@ -1125,6 +1140,7 @@ static void crawl_remote_refs(char *path)
1140
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
1141
1142
slot = get_active_slot();
1143
+ slot->results = &results;
1144
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
1145
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
1146
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
@@ -1137,7 +1153,7 @@ static void crawl_remote_refs(char *path)
1153
1154
if (start_active_slot(slot)) {
1155
run_active_slot(slot);
1140
- if (slot->curl_result == CURLE_OK) {
1156
+ if (results.curl_result == CURLE_OK) {
1157
ctx.name = xcalloc(10, 1);
1158
ctx.len = 0;
1159
ctx.cdata = NULL;
@@ -1171,6 +1187,7 @@ static void get_remote_object_list(unsigned char parent)
1187
{
1188
char *url;
1189
struct active_request_slot *slot;
1190
+ struct slot_results results;
1191
struct buffer in_buffer;
1192
struct buffer out_buffer;
1193
char *in_data;
@@ -1203,6 +1220,7 @@ static void get_remote_object_list(unsigned char parent)
1220
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
1221
1222
slot = get_active_slot();
1223
+ slot->results = &results;
1224
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
1225
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
1226
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
@@ -1215,7 +1233,7 @@ static void get_remote_object_list(unsigned char parent)
1233
1234
if (start_active_slot(slot)) {
1235
run_active_slot(slot);
1218
- if (slot->curl_result == CURLE_OK) {
1236
+ if (results.curl_result == CURLE_OK) {
1237
remote_dir_exists[parent] = 1;
1238
ctx.name = xcalloc(10, 1);
1239
ctx.len = 0;
@@ -1250,6 +1268,7 @@ static void get_remote_object_list(unsigned char parent)
1268
static int locking_available(void)
1269
{
1270
struct active_request_slot *slot;
1271
+ struct slot_results results;
1272
struct buffer in_buffer;
1273
struct buffer out_buffer;
1274
char *in_data;
@@ -1276,8 +1295,9 @@ static int locking_available(void)
1295
1296
dav_headers = curl_slist_append(dav_headers, "Depth: 0");
1297
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
1279
-
1298
+
1299
slot = get_active_slot();
1300
+ slot->results = &results;
1301
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
1302
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
1303
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
@@ -1290,7 +1310,7 @@ static int locking_available(void)
1310
1311
if (start_active_slot(slot)) {
1312
run_active_slot(slot);
1293
- if (slot->curl_result == CURLE_OK) {
1313
+ if (results.curl_result == CURLE_OK) {
1314
ctx.name = xcalloc(10, 1);
1315
ctx.len = 0;
1316
ctx.cdata = NULL;
@@ -1416,6 +1436,7 @@ static void get_delta(struct rev_info *revs, struct remote_lock *lock)
1436
static int update_remote(unsigned char *sha1, struct remote_lock *lock)
1437
{
1438
struct active_request_slot *slot;
1439
+ struct slot_results results;
1440
char *out_data;
1441
char *if_header;
1442
struct buffer out_buffer;
@@ -1437,6 +1458,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
1458
out_buffer.buffer = out_data;
1459
1460
slot = get_active_slot();
1461
+ slot->results = &results;
1462
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
1463
curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
1464
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
@@ -1451,10 +1473,10 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
1473
run_active_slot(slot);
1474
free(out_data);
1475
free(if_header);
1454
- if (slot->curl_result != CURLE_OK) {
1476
+ if (results.curl_result != CURLE_OK) {
1477
fprintf(stderr,
1478
"PUT error: curl result=%d, HTTP code=%ld\n",
1457
- slot->curl_result, slot->http_code);
1479
+ results.curl_result, results.http_code);
1480
/* We should attempt recovery? */
1481
return 0;
1482
}
http.c
+7
-1
@@ -339,6 +339,7 @@ struct active_request_slot *get_active_slot(void)
339
slot->in_use = 1;
340
slot->local = NULL;
341
slot->results = NULL;
342
+ slot->finished = NULL;
343
slot->callback_data = NULL;
344
slot->callback_func = NULL;
345
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, pragma_header);
@@ -389,8 +390,10 @@ void run_active_slot(struct active_request_slot *slot)
390
fd_set excfds;
391
int max_fd;
392
struct timeval select_timeout;
393
+ int finished = 0;
394
393
- while (slot->in_use) {
395
+ slot->finished = &finished;
396
+ while (!finished) {
397
data_received = 0;
398
step_active_slots();
399
@@ -442,6 +445,9 @@ static void finish_active_slot(struct active_request_slot *slot)
445
closedown_active_slot(slot);
446
curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
447
448
+ if (slot->finished != NULL)
449
+ (*slot->finished) = 1;
450
+
451
/* Store slot results so they can be read after the slot is reused */
452
if (slot->results != NULL) {
453
slot->results->curl_result = slot->curl_result;
http.h
+1
@@ -35,6 +35,7 @@ struct active_request_slot
35
int in_use;
36
CURLcode curl_result;
37
long http_code;
38
+ int *finished;
39
struct slot_results *results;
40
void *callback_data;
41
void (*callback_func)(void *data);