Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
libpkg: more accurately implement FETCH_TIMEOUT with libpkg
Kyle Evans committed 2 years ago
commit 546b43dfe65c08c5e38a964afbb212aa561f9957
parent 4ac0d5d
1 file changed +11 -2
modified libpkg/fetch_libcurl.c
@@ -35,6 +35,11 @@
#include "private/event.h"
#include "private/fetch.h"

+
/*
+
 * The choice of 2KB/s is arbitrary; at some point this should be configurable.
+
 */
+
#define	LIBPKG_SPEED_LIMIT	(2 * 1024)	/* bytes per second */
+

struct curl_repodata {
	CURLM *cm;
	CURLU *url;
@@ -453,8 +458,12 @@ retry:
	curl_easy_setopt(cl, CURLOPT_HEADERDATA, &data);
	curl_easy_setopt(cl, CURLOPT_TIMEVALUE, (long)fi->mtime);
	curl_easy_setopt(cl, CURLOPT_TIMECONDITION, (long)CURL_TIMECOND_IFMODSINCE);
-
	if (repo->fetcher->timeout > 0)
-
		curl_easy_setopt(cl, CURLOPT_TIMEOUT, repo->fetcher->timeout);
+
	if (repo->fetcher->timeout > 0) {
+
		curl_easy_setopt(cl, CURLOPT_CONNECTTIMEOUT, repo->fetcher->timeout);
+

+
		curl_easy_setopt(cl, CURLOPT_LOW_SPEED_LIMIT, LIBPKG_SPEED_LIMIT);
+
		curl_easy_setopt(cl, CURLOPT_LOW_SPEED_TIME, repo->fetcher->timeout);
+
	}

	long rc = curl_do_fetch(&data, cl, cr);
	time_t t;