4
4
#include "run-command.h"
5
5
#include "url.h"
6
6
7
- int data_received ;
8
7
int active_requests ;
9
8
int http_is_verbose ;
10
9
size_t http_post_buffer = 16 * LARGE_PACKET_MAX ;
@@ -99,13 +98,11 @@ size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
99
98
struct strbuf * buffer = buffer_ ;
100
99
101
100
strbuf_add (buffer , ptr , size );
102
- data_received ++ ;
103
101
return size ;
104
102
}
105
103
106
104
size_t fwrite_null (char * ptr , size_t eltsize , size_t nmemb , void * strbuf )
107
105
{
108
- data_received ++ ;
109
106
return eltsize * nmemb ;
110
107
}
111
108
@@ -536,7 +533,6 @@ struct active_request_slot *get_active_slot(void)
536
533
537
534
active_requests ++ ;
538
535
slot -> in_use = 1 ;
539
- slot -> local = NULL ;
540
536
slot -> results = NULL ;
541
537
slot -> finished = NULL ;
542
538
slot -> callback_data = NULL ;
@@ -640,8 +636,6 @@ void step_active_slots(void)
640
636
void run_active_slot (struct active_request_slot * slot )
641
637
{
642
638
#ifdef USE_CURL_MULTI
643
- long last_pos = 0 ;
644
- long current_pos ;
645
639
fd_set readfds ;
646
640
fd_set writefds ;
647
641
fd_set excfds ;
@@ -651,25 +645,33 @@ void run_active_slot(struct active_request_slot *slot)
651
645
652
646
slot -> finished = & finished ;
653
647
while (!finished ) {
654
- data_received = 0 ;
655
648
step_active_slots ();
656
649
657
- if (!data_received && slot -> local != NULL ) {
658
- current_pos = ftell (slot -> local );
659
- if (current_pos > last_pos )
660
- data_received ++ ;
661
- last_pos = current_pos ;
662
- }
650
+ if (slot -> in_use ) {
651
+ #if LIBCURL_VERSION_NUM >= 0x070f04
652
+ long curl_timeout ;
653
+ curl_multi_timeout (curlm , & curl_timeout );
654
+ if (curl_timeout == 0 ) {
655
+ continue ;
656
+ } else if (curl_timeout == -1 ) {
657
+ select_timeout .tv_sec = 0 ;
658
+ select_timeout .tv_usec = 50000 ;
659
+ } else {
660
+ select_timeout .tv_sec = curl_timeout / 1000 ;
661
+ select_timeout .tv_usec = (curl_timeout % 1000 ) * 1000 ;
662
+ }
663
+ #else
664
+ select_timeout .tv_sec = 0 ;
665
+ select_timeout .tv_usec = 50000 ;
666
+ #endif
663
667
664
- if (slot -> in_use && !data_received ) {
665
- max_fd = 0 ;
668
+ max_fd = -1 ;
666
669
FD_ZERO (& readfds );
667
670
FD_ZERO (& writefds );
668
671
FD_ZERO (& excfds );
669
- select_timeout .tv_sec = 0 ;
670
- select_timeout .tv_usec = 50000 ;
671
- select (max_fd , & readfds , & writefds ,
672
- & excfds , & select_timeout );
672
+ curl_multi_fdset (curlm , & readfds , & writefds , & excfds , & max_fd );
673
+
674
+ select (max_fd + 1 , & readfds , & writefds , & excfds , & select_timeout );
673
675
}
674
676
}
675
677
#else
@@ -814,7 +816,6 @@ static int http_request(const char *url, void *result, int target, int options)
814
816
headers = curl_slist_append (headers , buf .buf );
815
817
strbuf_reset (& buf );
816
818
}
817
- slot -> local = result ;
818
819
} else
819
820
curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION ,
820
821
fwrite_buffer );
@@ -862,7 +863,6 @@ static int http_request(const char *url, void *result, int target, int options)
862
863
ret = HTTP_START_FAILED ;
863
864
}
864
865
865
- slot -> local = NULL ;
866
866
curl_slist_free_all (headers );
867
867
strbuf_release (& buf );
868
868
@@ -1057,7 +1057,6 @@ void release_http_pack_request(struct http_pack_request *preq)
1057
1057
if (preq -> packfile != NULL ) {
1058
1058
fclose (preq -> packfile );
1059
1059
preq -> packfile = NULL ;
1060
- preq -> slot -> local = NULL ;
1061
1060
}
1062
1061
if (preq -> range_header != NULL ) {
1063
1062
curl_slist_free_all (preq -> range_header );
@@ -1079,7 +1078,6 @@ int finish_http_pack_request(struct http_pack_request *preq)
1079
1078
1080
1079
fclose (preq -> packfile );
1081
1080
preq -> packfile = NULL ;
1082
- preq -> slot -> local = NULL ;
1083
1081
1084
1082
lst = preq -> lst ;
1085
1083
while (* lst != p )
@@ -1148,7 +1146,6 @@ struct http_pack_request *new_http_pack_request(
1148
1146
}
1149
1147
1150
1148
preq -> slot = get_active_slot ();
1151
- preq -> slot -> local = preq -> packfile ;
1152
1149
curl_easy_setopt (preq -> slot -> curl , CURLOPT_FILE , preq -> packfile );
1153
1150
curl_easy_setopt (preq -> slot -> curl , CURLOPT_WRITEFUNCTION , fwrite );
1154
1151
curl_easy_setopt (preq -> slot -> curl , CURLOPT_URL , preq -> url );
@@ -1205,7 +1202,6 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
1205
1202
git_SHA1_Update (& freq -> c , expn ,
1206
1203
sizeof (expn ) - freq -> stream .avail_out );
1207
1204
} while (freq -> stream .avail_in && freq -> zret == Z_OK );
1208
- data_received ++ ;
1209
1205
return size ;
1210
1206
}
1211
1207
0 commit comments