@@ -619,6 +619,11 @@ static int download_add_url(int i, SEXP scmd, const char *mode,
619619 }
620620 curl_easy_setopt (c -> hnd [i ], CURLOPT_URL , url );
621621 curl_easy_setopt (c -> hnd [i ], CURLOPT_FAILONERROR , 1L );
622+ #if LIBCURL_VERSION_NUM >= 0x072b00
623+ /* Wait for the first conneciton to the server to reveal whether it
624+ allows multi-plexing before starting a new connection. */
625+ curl_easy_setopt (c -> hnd [i ], CURLOPT_PIPEWAIT , 1L );
626+ #endif
622627 /* Users will normally expect to follow redirections, although
623628 that is not the default in either curl or libcurl. */
624629 curlCommon (c -> hnd [i ], 1 , 1 );
@@ -721,9 +726,8 @@ static int download_add_one_url(int *i, SEXP scmd, const char *mode, int quiet,
721726
722727/* Add at most n URLs to the multi-handle, if possible. Bail out when an URL
723728 cannot be added (do not advance, do not report errors). The idea is that
724- when an URL cannot be added, it can be due to lack of resources (i.e.
725- connections), so it makes sense to try later. Advance only when URLs have
726- been added. */
729+ when an URL cannot be added, it can be due to lack of resources, so it makes
730+ sense to try later. Advance only when URLs have been added. */
727731static int download_try_add_urls (int * i , int n , SEXP scmd ,
728732 const char * mode , int quiet , int single ,
729733 download_cleanup_info * c )
@@ -888,8 +892,20 @@ in_do_curlDownload(SEXP call, SEXP op, SEXP args, SEXP rho)
888892 When no URL is active, at least one must be added to ensure progress.
889893 But if possible we add more (up to MAX_CONCURRENT_URLS) - we do that
890894 only optionally to reduce the risks of failing due to lack of resources.
895+
896+ Note that an URL may be added but the transfer be delayed. Currently
897+ this can happen when the limit on the number of connections per host
898+ is reached, but in principle curl can do it also in other cases.
891899 */
892900
901+ #if LIBCURL_VERSION_NUM >= 0x071e00
902+ /* Most current browsers would use at least 6. RFC2616 recommends at most
903+ 2, but this has been removed in RFC7230. The limit is important for
904+ HTTP 1.1 transfers. HTTP 2 (with CURLOPT_PIPEWAIT) would multiplex
905+ downloads from the same server through a single connection. */
906+ curl_multi_setopt (mhnd , CURLMOPT_MAX_HOST_CONNECTIONS , 6L );
907+ #endif
908+
893909 if (download_add_one_url (& next_url , scmd , mode , quiet , single , & c )) {
894910 // no dest files could be opened, so bail out
895911 endcontext (& cntxt );
0 commit comments