44#include "run-command.h"
55#include "url.h"
66
7- int data_received ;
87int active_requests ;
98int http_is_verbose ;
109size_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_)
9998 struct strbuf * buffer = buffer_ ;
10099
101100 strbuf_add (buffer , ptr , size );
102- data_received ++ ;
103101 return size ;
104102}
105103
106104size_t fwrite_null (char * ptr , size_t eltsize , size_t nmemb , void * strbuf )
107105{
108- data_received ++ ;
109106 return eltsize * nmemb ;
110107}
111108
@@ -536,7 +533,6 @@ struct active_request_slot *get_active_slot(void)
536533
537534 active_requests ++ ;
538535 slot -> in_use = 1 ;
539- slot -> local = NULL ;
540536 slot -> results = NULL ;
541537 slot -> finished = NULL ;
542538 slot -> callback_data = NULL ;
@@ -640,8 +636,6 @@ void step_active_slots(void)
640636void run_active_slot (struct active_request_slot * slot )
641637{
642638#ifdef USE_CURL_MULTI
643- long last_pos = 0 ;
644- long current_pos ;
645639 fd_set readfds ;
646640 fd_set writefds ;
647641 fd_set excfds ;
@@ -651,25 +645,33 @@ void run_active_slot(struct active_request_slot *slot)
651645
652646 slot -> finished = & finished ;
653647 while (!finished ) {
654- data_received = 0 ;
655648 step_active_slots ();
656649
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
663667
664- if (slot -> in_use && !data_received ) {
665- max_fd = 0 ;
668+ max_fd = -1 ;
666669 FD_ZERO (& readfds );
667670 FD_ZERO (& writefds );
668671 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 );
673675 }
674676 }
675677#else
@@ -814,7 +816,6 @@ static int http_request(const char *url, void *result, int target, int options)
814816 headers = curl_slist_append (headers , buf .buf );
815817 strbuf_reset (& buf );
816818 }
817- slot -> local = result ;
818819 } else
819820 curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION ,
820821 fwrite_buffer );
@@ -862,7 +863,6 @@ static int http_request(const char *url, void *result, int target, int options)
862863 ret = HTTP_START_FAILED ;
863864 }
864865
865- slot -> local = NULL ;
866866 curl_slist_free_all (headers );
867867 strbuf_release (& buf );
868868
@@ -1057,7 +1057,6 @@ void release_http_pack_request(struct http_pack_request *preq)
10571057 if (preq -> packfile != NULL ) {
10581058 fclose (preq -> packfile );
10591059 preq -> packfile = NULL ;
1060- preq -> slot -> local = NULL ;
10611060 }
10621061 if (preq -> range_header != NULL ) {
10631062 curl_slist_free_all (preq -> range_header );
@@ -1079,7 +1078,6 @@ int finish_http_pack_request(struct http_pack_request *preq)
10791078
10801079 fclose (preq -> packfile );
10811080 preq -> packfile = NULL ;
1082- preq -> slot -> local = NULL ;
10831081
10841082 lst = preq -> lst ;
10851083 while (* lst != p )
@@ -1148,7 +1146,6 @@ struct http_pack_request *new_http_pack_request(
11481146 }
11491147
11501148 preq -> slot = get_active_slot ();
1151- preq -> slot -> local = preq -> packfile ;
11521149 curl_easy_setopt (preq -> slot -> curl , CURLOPT_FILE , preq -> packfile );
11531150 curl_easy_setopt (preq -> slot -> curl , CURLOPT_WRITEFUNCTION , fwrite );
11541151 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,
12051202 git_SHA1_Update (& freq -> c , expn ,
12061203 sizeof (expn ) - freq -> stream .avail_out );
12071204 } while (freq -> stream .avail_in && freq -> zret == Z_OK );
1208- data_received ++ ;
12091205 return size ;
12101206}
12111207
0 commit comments