mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-21 03:32:35 +03:00
remove curl fetchers use of the wallclock API
The wallclock() API uses gettimeofday which can be affected by the the systems clock being changed etc. The curl fetcher usage of this API is to generate a timing delta and does not cope with the gettimeofday issues. This changes the fetcher to use the nsutils library monotonic time function which does not suffer from the issues with gettimeofday.
This commit is contained in:
parent
afea659fef
commit
798654f910
@ -41,6 +41,7 @@
|
|||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
#include <libwapcaplet/libwapcaplet.h>
|
#include <libwapcaplet/libwapcaplet.h>
|
||||||
|
#include <nsutils/time.h>
|
||||||
|
|
||||||
#include "utils/corestrings.h"
|
#include "utils/corestrings.h"
|
||||||
#include "utils/nsoption.h"
|
#include "utils/nsoption.h"
|
||||||
@ -58,6 +59,8 @@
|
|||||||
#include "content/fetchers/curl.h"
|
#include "content/fetchers/curl.h"
|
||||||
#include "content/urldb.h"
|
#include "content/urldb.h"
|
||||||
|
|
||||||
|
/** maximum number of progress notifications per second */
|
||||||
|
#define UPDATES_PER_SECOND 2
|
||||||
|
|
||||||
/** SSL certificate info */
|
/** SSL certificate info */
|
||||||
struct cert_info {
|
struct cert_info {
|
||||||
@ -86,7 +89,7 @@ struct curl_fetch_info {
|
|||||||
struct curl_httppost *post_multipart; /**< Multipart post data, or 0. */
|
struct curl_httppost *post_multipart; /**< Multipart post data, or 0. */
|
||||||
#define MAX_CERTS 10
|
#define MAX_CERTS 10
|
||||||
struct cert_info cert_data[MAX_CERTS]; /**< HTTPS certificate data */
|
struct cert_info cert_data[MAX_CERTS]; /**< HTTPS certificate data */
|
||||||
unsigned int last_progress_update; /**< Time of last progress update */
|
uint64_t last_progress_update; /**< Time of last progress update */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cache_handle {
|
struct cache_handle {
|
||||||
@ -757,8 +760,7 @@ static bool fetch_curl_process_headers(struct curl_fetch_info *f)
|
|||||||
|
|
||||||
f->had_headers = true;
|
f->had_headers = true;
|
||||||
|
|
||||||
if (!f->http_code)
|
if (!f->http_code) {
|
||||||
{
|
|
||||||
code = curl_easy_getinfo(f->curl_handle, CURLINFO_HTTP_CODE,
|
code = curl_easy_getinfo(f->curl_handle, CURLINFO_HTTP_CODE,
|
||||||
&f->http_code);
|
&f->http_code);
|
||||||
fetch_set_http_code(f->fetch_handle, f->http_code);
|
fetch_set_http_code(f->fetch_handle, f->http_code);
|
||||||
@ -1082,24 +1084,24 @@ static int fetch_curl_progress(void *clientp, double dltotal, double dlnow,
|
|||||||
{
|
{
|
||||||
static char fetch_progress_buffer[256]; /**< Progress buffer for cURL */
|
static char fetch_progress_buffer[256]; /**< Progress buffer for cURL */
|
||||||
struct curl_fetch_info *f = (struct curl_fetch_info *) clientp;
|
struct curl_fetch_info *f = (struct curl_fetch_info *) clientp;
|
||||||
unsigned int time_now_cs;
|
uint64_t time_now_ms;
|
||||||
fetch_msg msg;
|
fetch_msg msg;
|
||||||
|
|
||||||
if (f->abort)
|
if (f->abort) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
msg.type = FETCH_PROGRESS;
|
msg.type = FETCH_PROGRESS;
|
||||||
msg.data.progress = fetch_progress_buffer;
|
msg.data.progress = fetch_progress_buffer;
|
||||||
|
|
||||||
/* Rate limit each fetch's progress notifications to 2 a second */
|
/* Rate limit each fetch's progress notifications */
|
||||||
#define UPDATES_PER_SECOND 2
|
nsu_getmonotonic_ms(&time_now_ms);
|
||||||
#define UPDATE_DELAY_CS (100 / UPDATES_PER_SECOND)
|
#define UPDATE_DELAY_MS (1000 / UPDATES_PER_SECOND)
|
||||||
time_now_cs = wallclock();
|
if (time_now_ms - f->last_progress_update < UPDATE_DELAY_MS) {
|
||||||
if (time_now_cs - f->last_progress_update < UPDATE_DELAY_CS)
|
|
||||||
return 0;
|
return 0;
|
||||||
f->last_progress_update = time_now_cs;
|
}
|
||||||
#undef UPDATE_DELAY_CS
|
#undef UPDATE_DELAY_MS
|
||||||
#undef UPDATES_PERS_SECOND
|
f->last_progress_update = time_now_ms;
|
||||||
|
|
||||||
if (dltotal > 0) {
|
if (dltotal > 0) {
|
||||||
snprintf(fetch_progress_buffer, 255,
|
snprintf(fetch_progress_buffer, 255,
|
||||||
|
Loading…
Reference in New Issue
Block a user