summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2017-07-21 13:16:50 +0200
committerDaniel Stenberg <daniel@haxx.se>2017-07-21 13:18:46 +0200
commit4c5b3ff8497ae788b3f3937cc6eeddcaa4d93397 (patch)
tree89cf483bc804081c68974de672cf830eb21e9ace
parentda6aa3f76382e6ddf471dad198c507b7c7704ffb (diff)
downloadcurl-4c5b3ff8497ae788b3f3937cc6eeddcaa4d93397.tar.gz
timeval: introduce curlval as a struct timeval replacement
... to make all libcurl internals able to use the same data types for the struct members. The timeval struct differs subtly on several platforms so it makes it cumbersome to use everywhere. Ref: #1652
-rw-r--r--lib/asyn-ares.c4
-rw-r--r--lib/conncache.h2
-rw-r--r--lib/connect.c8
-rw-r--r--lib/connect.h4
-rw-r--r--lib/easy.c8
-rw-r--r--lib/ftp.c2
-rw-r--r--lib/multi.c30
-rw-r--r--lib/multihandle.h2
-rw-r--r--lib/pingpong.h2
-rw-r--r--lib/progress.c12
-rw-r--r--lib/progress.h6
-rw-r--r--lib/rand.c2
-rw-r--r--lib/select.c20
-rw-r--r--lib/speedcheck.c4
-rw-r--r--lib/speedcheck.h4
-rw-r--r--lib/splay.c18
-rw-r--r--lib/splay.h13
-rw-r--r--lib/telnet.c2
-rw-r--r--lib/timeval.c37
-rw-r--r--lib/timeval.h11
-rw-r--r--lib/url.c6
-rw-r--r--lib/urldata.h32
-rw-r--r--lib/vtls/openssl.c13
-rw-r--r--tests/server/util.c8
-rw-r--r--tests/unit/unit1303.c4
-rw-r--r--tests/unit/unit1309.c13
-rw-r--r--tests/unit/unit1399.c2
-rw-r--r--tests/unit/unit1606.c2
28 files changed, 144 insertions, 127 deletions
diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c
index 11a914f82..c7b3042ac 100644
--- a/lib/asyn-ares.c
+++ b/lib/asyn-ares.c
@@ -355,7 +355,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data;
long timeout;
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
struct Curl_dns_entry *temp_entry;
if(entry)
@@ -400,7 +400,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else {
- struct timeval now2 = Curl_tvnow();
+ struct curlval now2 = Curl_tvnow();
time_t timediff = Curl_tvdiff(now2, now); /* spent time */
if(timediff <= 0)
timeout -= 1; /* always deduct at least 1 */
diff --git a/lib/conncache.h b/lib/conncache.h
index f976cfdb4..4a89ca363 100644
--- a/lib/conncache.h
+++ b/lib/conncache.h
@@ -27,7 +27,7 @@ struct conncache {
struct curl_hash hash;
size_t num_connections;
long next_connection_id;
- struct timeval last_cleanup;
+ struct curlval last_cleanup;
};
#define BUNDLE_NO_MULTIUSE -1
diff --git a/lib/connect.c b/lib/connect.c
index 8063cf005..78f89bbd2 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -180,12 +180,12 @@ singleipconnect(struct connectdata *conn,
* @unittest: 1303
*/
time_t Curl_timeleft(struct Curl_easy *data,
- struct timeval *nowp,
+ struct curlval *nowp,
bool duringconnect)
{
int timeout_set = 0;
time_t timeout_ms = duringconnect?DEFAULT_CONNECT_TIMEOUT:0;
- struct timeval now;
+ struct curlval now;
/* if a timeout is set, use the most restrictive one */
@@ -723,7 +723,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
CURLcode result = CURLE_OK;
time_t allow;
int error = 0;
- struct timeval now;
+ struct curlval now;
int rc;
int i;
@@ -1136,7 +1136,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
const struct Curl_dns_entry *remotehost)
{
struct Curl_easy *data = conn->data;
- struct timeval before = Curl_tvnow();
+ struct curlval before = Curl_tvnow();
CURLcode result = CURLE_COULDNT_CONNECT;
time_t timeout_ms = Curl_timeleft(data, &before, TRUE);
diff --git a/lib/connect.h b/lib/connect.h
index 44bdb1051..83cd23085 100644
--- a/lib/connect.h
+++ b/lib/connect.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -36,7 +36,7 @@ CURLcode Curl_connecthost(struct connectdata *conn,
/* generic function that returns how much time there's left to run, according
to the timeouts set */
time_t Curl_timeleft(struct Curl_easy *data,
- struct timeval *nowp,
+ struct curlval *nowp,
bool duringconnect);
#define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
diff --git a/lib/easy.c b/lib/easy.c
index 2b1ce9e8a..93a5258ef 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -572,8 +572,8 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
int numfds=0;
int pollrc;
int i;
- struct timeval before;
- struct timeval after;
+ struct curlval before;
+ struct curlval after;
/* populate the fds[] array */
for(m = ev->list, f=&fds[0]; m; m = m->next) {
@@ -670,7 +670,7 @@ static CURLcode easy_transfer(struct Curl_multi *multi)
bool done = FALSE;
CURLMcode mcode = CURLM_OK;
CURLcode result = CURLE_OK;
- struct timeval before;
+ struct curlval before;
int without_fds = 0; /* count number of consecutive returns from
curl_multi_wait() without any filedescriptors */
@@ -683,7 +683,7 @@ static CURLcode easy_transfer(struct Curl_multi *multi)
if(!mcode) {
if(!rc) {
- struct timeval after = curlx_tvnow();
+ struct curlval after = curlx_tvnow();
/* If it returns without any filedescriptor instantly, we need to
avoid busy-looping during periods where it has nothing particular
diff --git a/lib/ftp.c b/lib/ftp.c
index 6d1f24a32..24a95a6e4 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -336,7 +336,7 @@ static time_t ftp_timeleft_accept(struct Curl_easy *data)
{
time_t timeout_ms = DEFAULT_ACCEPT_TIMEOUT;
time_t other;
- struct timeval now;
+ struct curlval now;
if(data->set.accepttimeout > 0)
timeout_ms = data->set.accepttimeout;
diff --git a/lib/multi.c b/lib/multi.c
index 5753f58f7..cac379ce5 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -70,7 +70,7 @@ static void singlesocket(struct Curl_multi *multi,
struct Curl_easy *data);
static int update_timer(struct Curl_multi *multi);
-static CURLMcode add_next_timeout(struct timeval now,
+static CURLMcode add_next_timeout(struct curlval now,
struct Curl_multi *multi,
struct Curl_easy *d);
static CURLMcode multi_timeout(struct Curl_multi *multi,
@@ -1297,7 +1297,7 @@ static CURLcode multi_do_more(struct connectdata *conn, int *complete)
}
static CURLMcode multi_runsingle(struct Curl_multi *multi,
- struct timeval now,
+ struct curlval now,
struct Curl_easy *data)
{
struct Curl_message *msg = NULL;
@@ -2142,7 +2142,7 @@ CURLMcode curl_multi_perform(struct Curl_multi *multi, int *running_handles)
struct Curl_easy *data;
CURLMcode returncode=CURLM_OK;
struct Curl_tree *t;
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE;
@@ -2492,11 +2492,11 @@ void Curl_multi_closed(struct connectdata *conn, curl_socket_t s)
* The splay tree only has each sessionhandle as a single node and the nearest
* timeout is used to sort it on.
*/
-static CURLMcode add_next_timeout(struct timeval now,
+static CURLMcode add_next_timeout(struct curlval now,
struct Curl_multi *multi,
struct Curl_easy *d)
{
- struct timeval *tv = &d->state.expiretime;
+ struct curlval *tv = &d->state.expiretime;
struct curl_llist *list = &d->state.timeoutlist;
struct curl_llist_element *e;
struct time_node *node = NULL;
@@ -2547,7 +2547,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
CURLMcode result = CURLM_OK;
struct Curl_easy *data = NULL;
struct Curl_tree *t;
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
if(checkall) {
/* *perform() deals with running_handles on its own */
@@ -2773,11 +2773,11 @@ CURLMcode curl_multi_socket_all(struct Curl_multi *multi, int *running_handles)
static CURLMcode multi_timeout(struct Curl_multi *multi,
long *timeout_ms)
{
- static struct timeval tv_zero = {0, 0};
+ static struct curlval tv_zero = {0, 0};
if(multi->timetree) {
/* we have a tree of expire times */
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
/* splay the lowest to the bottom */
multi->timetree = Curl_splay(tv_zero, multi->timetree);
@@ -2829,7 +2829,7 @@ static int update_timer(struct Curl_multi *multi)
return -1;
}
if(timeout_ms < 0) {
- static const struct timeval none={0, 0};
+ static const struct curlval none={0, 0};
if(Curl_splaycomparekeys(none, multi->timer_lastcall)) {
multi->timer_lastcall = none;
/* there's no timeout now but there was one previously, tell the app to
@@ -2880,7 +2880,7 @@ multi_deltimeout(struct Curl_easy *data, expire_id eid)
*/
static CURLMcode
multi_addtimeout(struct Curl_easy *data,
- struct timeval *stamp,
+ struct curlval *stamp,
expire_id eid)
{
struct curl_llist_element *e;
@@ -2928,9 +2928,9 @@ multi_addtimeout(struct Curl_easy *data,
void Curl_expire(struct Curl_easy *data, time_t milli, expire_id id)
{
struct Curl_multi *multi = data->multi;
- struct timeval *nowp = &data->state.expiretime;
+ struct curlval *nowp = &data->state.expiretime;
int rc;
- struct timeval set;
+ struct curlval set;
/* this is only interesting while there is still an associated multi struct
remaining! */
@@ -2940,8 +2940,8 @@ void Curl_expire(struct Curl_easy *data, time_t milli, expire_id id)
DEBUGASSERT(id < EXPIRE_LAST);
set = Curl_tvnow();
- set.tv_sec += (long)(milli/1000);
- set.tv_usec += (long)(milli%1000)*1000;
+ set.tv_sec += milli/1000;
+ set.tv_usec += (unsigned int)(milli%1000)*1000;
if(set.tv_usec >= 1000000) {
set.tv_sec++;
@@ -3003,7 +3003,7 @@ void Curl_expire_done(struct Curl_easy *data, expire_id id)
void Curl_expire_clear(struct Curl_easy *data)
{
struct Curl_multi *multi = data->multi;
- struct timeval *nowp = &data->state.expiretime;
+ struct curlval *nowp = &data->state.expiretime;
int rc;
/* this is only interesting while there is still an associated multi struct
diff --git a/lib/multihandle.h b/lib/multihandle.h
index e6ffbf5b6..35a3dfe05 100644
--- a/lib/multihandle.h
+++ b/lib/multihandle.h
@@ -148,7 +148,7 @@ struct Curl_multi {
/* timer callback and user data pointer for the *socket() API */
curl_multi_timer_callback timer_cb;
void *timer_userp;
- struct timeval timer_lastcall; /* the fixed time for the timeout for the
+ struct curlval timer_lastcall; /* the fixed time for the timeout for the
previous callback */
};
diff --git a/lib/pingpong.h b/lib/pingpong.h
index ee1a59b51..1b0a64dc6 100644
--- a/lib/pingpong.h
+++ b/lib/pingpong.h
@@ -58,7 +58,7 @@ struct pingpong {
server */
size_t sendleft; /* number of bytes left to send from the sendthis buffer */
size_t sendsize; /* total size of the sendthis buffer */
- struct timeval response; /* set to Curl_tvnow() when a command has been sent
+ struct curlval response; /* set to Curl_tvnow() when a command has been sent
off, used to time-out response reading */
long response_time; /* When no timeout is given, this is the amount of
milliseconds we await for a server response. */
diff --git a/lib/progress.c b/lib/progress.c
index e92d96fdc..0d96f9b50 100644
--- a/lib/progress.c
+++ b/lib/progress.c
@@ -166,7 +166,7 @@ void Curl_pgrsResetTimesSizes(struct Curl_easy *data)
*/
void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
{
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
time_t *delta = NULL;
switch(timer) {
@@ -260,8 +260,8 @@ void Curl_pgrsStartNow(struct Curl_easy *data)
long Curl_pgrsLimitWaitTime(curl_off_t cursize,
curl_off_t startsize,
curl_off_t limit,
- struct timeval start,
- struct timeval now)
+ struct curlval start,
+ struct curlval now)
{
curl_off_t size = cursize - startsize;
time_t minimum;
@@ -287,7 +287,7 @@ long Curl_pgrsLimitWaitTime(curl_off_t cursize,
void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
{
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
data->progress.downloaded = size;
@@ -305,7 +305,7 @@ void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size)
{
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
data->progress.uploaded = size;
@@ -351,7 +351,7 @@ void Curl_pgrsSetUploadSize(struct Curl_easy *data, curl_off_t size)
*/
int Curl_pgrsUpdate(struct connectdata *conn)
{
- struct timeval now;
+ struct curlval now;
int result;
char max5[6][10];
curl_off_t dlpercen=0;
diff --git a/lib/progress.h b/lib/progress.h
index 155ff04fe..eca171db0 100644
--- a/lib/progress.h
+++ b/lib/progress.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -52,8 +52,8 @@ void Curl_pgrsTime(struct Curl_easy *data, timerid timer);
long Curl_pgrsLimitWaitTime(curl_off_t cursize,
curl_off_t startsize,
curl_off_t limit,
- struct timeval start,
- struct timeval now);
+ struct curlval start,
+ struct curlval now);
/* Don't show progress for sizes smaller than: */
#define LEAST_SIZE_PROGRESS BUFSIZE
diff --git a/lib/rand.c b/lib/rand.c
index b6f40ac0a..3eaecefe6 100644
--- a/lib/rand.c
+++ b/lib/rand.c
@@ -86,7 +86,7 @@ static CURLcode randit(struct Curl_easy *data, unsigned int *rnd)
#endif
if(!seeded) {
- struct timeval now = curlx_tvnow();
+ struct curlval now = curlx_tvnow();
infof(data, "WARNING: Using weak random seed\n");
randseed += (unsigned int)now.tv_usec + (unsigned int)now.tv_sec;
randseed = randseed * 1103515245 + 12345;
diff --git a/lib/select.c b/lib/select.c
index f49314b34..bc100bf8c 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -76,9 +76,9 @@ int Curl_wait_ms(int timeout_ms)
{
#if !defined(MSDOS) && !defined(USE_WINSOCK)
#ifndef HAVE_POLL_FINE
- struct timeval pending_tv;
+ struct curlval pending_tv;
#endif
- struct timeval initial_tv;
+ struct curlval initial_tv;
int pending_ms;
int error;
#endif
@@ -151,14 +151,14 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
struct pollfd pfd[3];
int num;
#else
- struct timeval pending_tv;
- struct timeval *ptimeout;
+ struct curlval pending_tv;
+ struct curlval *ptimeout;
fd_set fds_read;
fd_set fds_write;
fd_set fds_err;
curl_socket_t maxfd;
#endif
- struct timeval initial_tv = {0, 0};
+ struct curlval initial_tv = {0, 0};
int pending_ms = 0;
int error;
int r;
@@ -391,14 +391,14 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
{
#ifndef HAVE_POLL_FINE
- struct timeval pending_tv;
- struct timeval *ptimeout;
+ struct curlval pending_tv;
+ struct curlval *ptimeout;
fd_set fds_read;
fd_set fds_write;
fd_set fds_err;
curl_socket_t maxfd;
#endif
- struct timeval initial_tv = {0, 0};
+ struct curlval initial_tv = {0, 0};
bool fds_none = TRUE;
unsigned int i;
int pending_ms = 0;
@@ -571,8 +571,8 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
*
* Return values are the same as select's.
*/
-int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes,
- fd_set* excepts, struct timeval* tv)
+int tpf_select_libcurl(int maxfds, fd_set *reads, fd_set *writes,
+ fd_set *excepts, struct curlval *tv)
{
int rc;
diff --git a/lib/speedcheck.c b/lib/speedcheck.c
index 8addedde5..6f15ee5dd 100644
--- a/lib/speedcheck.c
+++ b/lib/speedcheck.c
@@ -30,14 +30,14 @@
void Curl_speedinit(struct Curl_easy *data)
{
- memset(&data->state.keeps_speed, 0, sizeof(struct timeval));
+ memset(&data->state.keeps_speed, 0, sizeof(struct curlval));
}
/*
* @unittest: 1606
*/
CURLcode Curl_speedcheck(struct Curl_easy *data,
- struct timeval now)
+ struct curlval now)
{
if((data->progress.current_speed >= 0) && data->set.low_speed_time) {
if(data->progress.current_speed < data->set.low_speed_limit) {
diff --git a/lib/speedcheck.h b/lib/speedcheck.h
index 7dbe3d6d7..35de448ec 100644
--- a/lib/speedcheck.h
+++ b/lib/speedcheck.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -28,6 +28,6 @@
void Curl_speedinit(struct Curl_easy *data);
CURLcode Curl_speedcheck(struct Curl_easy *data,
- struct timeval now);
+ struct curlval now);
#endif /* HEADER_CURL_SPEEDCHECK_H */
diff --git a/lib/splay.c b/lib/splay.c
index 1b301f95d..7e6ff3317 100644
--- a/lib/splay.c
+++ b/lib/splay.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1997 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1997 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -37,7 +37,7 @@
* Splay using the key i (which may or may not be in the tree.) The starting
* root is t.
*/
-struct Curl_tree *Curl_splay(struct timeval i,
+struct Curl_tree *Curl_splay(struct curlval i,
struct Curl_tree *t)
{
struct Curl_tree N, *l, *r, *y;
@@ -97,11 +97,11 @@ struct Curl_tree *Curl_splay(struct timeval i,
*
* @unittest: 1309
*/
-struct Curl_tree *Curl_splayinsert(struct timeval i,
+struct Curl_tree *Curl_splayinsert(struct curlval i,
struct Curl_tree *t,
struct Curl_tree *node)
{
- static const struct timeval KEY_NOTUSED = {-1, -1}; /* will *NEVER* appear */
+ static const struct curlval KEY_NOTUSED = {-1, -1}; /* will *NEVER* appear */
if(node == NULL)
return t;
@@ -149,11 +149,11 @@ struct Curl_tree *Curl_splayinsert(struct timeval i,
/* Finds and deletes the best-fit node from the tree. Return a pointer to the
resulting tree. best-fit means the smallest node if it is not larger than
the key */
-struct Curl_tree *Curl_splaygetbest(struct timeval i,
- struct Curl_tree *t,
- struct Curl_tree **removed)
+struct Curl_tree *Curl_splaygetbest(struct curlval i,
+ struct Curl_tree *t,
+ struct Curl_tree **removed)
{
- static struct timeval tv_zero = {0, 0};
+ static struct curlval tv_zero = {0, 0};
struct Curl_tree *x;
if(!t) {
@@ -209,7 +209,7 @@ int Curl_splayremovebyaddr(struct Curl_tree *t,
struct Curl_tree *removenode,
struct Curl_tree **newroot)
{
- static const struct timeval KEY_NOTUSED = {-1, -1}; /* will *NEVER* appear */
+ static const struct curlval KEY_NOTUSED = {-1, -1}; /* will *NEVER* appear */
struct Curl_tree *x;
if(!t || !removenode)
diff --git a/lib/splay.h b/lib/splay.h
index da81894d1..d91a26ff5 100644
--- a/lib/splay.h
+++ b/lib/splay.h
@@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1997 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1997 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -22,30 +22,31 @@
*
***************************************************************************/
#include "curl_setup.h"
+#include "timeval.h"
struct Curl_tree {
struct Curl_tree *smaller; /* smaller node */
struct Curl_tree *larger; /* larger node */
struct Curl_tree *samen; /* points to the next node with identical key */
struct Curl_tree *samep; /* points to the prev node with identical key */
- struct timeval key; /* this node's "sort" key */
+ struct curlval key; /* this node's "sort" key */
void *payload; /* data the splay code doesn't care about */
};
-struct Curl_tree *Curl_splay(struct timeval i,
+struct Curl_tree *Curl_splay(struct curlval i,
struct Curl_tree *t);
-struct Curl_tree *Curl_splayinsert(struct timeval key,
+struct Curl_tree *Curl_splayinsert(struct curlval key,
struct Curl_tree *t,
struct Curl_tree *newnode);
#if 0
-struct Curl_tree *Curl_splayremove(struct timeval key,
+struct Curl_tree *Curl_splayremove(struct curlval key,
struct Curl_tree *t,
struct Curl_tree **removed);
#endif
-struct Curl_tree *Curl_splaygetbest(struct timeval key,
+struct Curl_tree *Curl_splaygetbest(struct curlval key,
struct Curl_tree *t,
struct Curl_tree **removed);
diff --git a/lib/telnet.c b/lib/telnet.c
index 269b193d0..9ec43eab4 100644
--- a/lib/telnet.c
+++ b/lib/telnet.c
@@ -1327,7 +1327,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
curl_off_t total_ul = 0;
#endif
ssize_t nread;
- struct timeval now;
+ struct curlval now;
bool keepon = TRUE;
char *buf = data->state.buffer;
struct TELNET *tn;
diff --git a/lib/timeval.c b/lib/timeval.c
index aff53cddc..a6673cadb 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -31,7 +31,7 @@ struct timeval curlx_tvnow(void)
** to nowadays. Returns milliseconds elapsed since last system boot,
** increases monotonically and wraps once 49.7 days have elapsed.
*/
- struct timeval now;
+ struct curlval now;
#if !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_VISTA) || \
(_WIN32_WINNT < _WIN32_WINNT_VISTA)
DWORD milliseconds = GetTickCount();
@@ -48,7 +48,7 @@ struct timeval curlx_tvnow(void)
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
-struct timeval curlx_tvnow(void)
+struct curlval curlx_tvnow(void)
{
/*
** clock_gettime() is granted to be increased monotonically when the
@@ -58,10 +58,11 @@ struct timeval curlx_tvnow(void)
** system has started up.
*/
struct timeval now;
+ struct curlval cnow;
struct timespec tsnow;
if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
- now.tv_sec = tsnow.tv_sec;
- now.tv_usec = tsnow.tv_nsec / 1000;
+ cnow.tv_sec = tsnow.tv_sec;
+ cnow.tv_usec = (unsigned int)(tsnow.tv_nsec / 1000);
}
/*
** Even when the configure process has truly detected monotonic clock
@@ -69,20 +70,23 @@ struct timeval curlx_tvnow(void)
** run-time. When this occurs simply fallback to other time source.
*/
#ifdef HAVE_GETTIMEOFDAY
- else
+ else {
(void)gettimeofday(&now, NULL);
+ cnow.tv_sec = now.tv_sec;
+ cnow.tv_usec = (unsigned int)now.tv_usec;
+ }
#else
else {
- now.tv_sec = (long)time(NULL);
- now.tv_usec = 0;
+ cnow.tv_sec = time(NULL);
+ cnow.tv_usec = 0;
}
#endif
- return now;
+ return cnow;
}
#elif defined(HAVE_GETTIMEOFDAY)
-struct timeval curlx_tvnow(void)
+struct curlval curlx_tvnow(void)
{
/*
** gettimeofday() is not granted to be increased monotonically, due to
@@ -90,19 +94,22 @@ struct timeval curlx_tvnow(void)
** forward or backward in time.
*/
struct timeval now;
+ struct curlval ret;
(void)gettimeofday(&now, NULL);
- return now;
+ ret.tv_sec = now.tv_sec;
+ ret.tv_usec = now.tv_usec;
+ return ret;
}
#else
-struct timeval curlx_tvnow(void)
+struct curlval curlx_tvnow(void)
{
/*
** time() returns the value of time in seconds since the Epoch.
*/
- struct timeval now;
- now.tv_sec = (long)time(NULL);
+ struct curlval now;
+ now.tv_sec = time(NULL);
now.tv_usec = 0;
return now;
}
@@ -116,7 +123,7 @@ struct timeval curlx_tvnow(void)
* Returns: the time difference in number of milliseconds. For large diffs it
* returns 0x7fffffff on 32bit time_t systems.
*/
-time_t curlx_tvdiff(struct timeval newer, struct timeval older)
+time_t curlx_tvdiff(struct curlval newer, struct curlval older)
{
#if SIZEOF_TIME_T < 8
/* for 32bit time_t systems, add a precaution to avoid overflow for really
@@ -136,7 +143,7 @@ time_t curlx_tvdiff(struct timeval newer, struct timeval older)
* Returns: the time difference in number of microseconds. For too large diffs
* it returns max value.
*/
-time_t Curl_tvdiff_us(struct timeval newer, struct timeval older)
+time_t Curl_tvdiff_us(struct curlval newer, struct curlval older)
{
time_t diff = newer.tv_sec-older.tv_sec;
#if SIZEOF_TIME_T < 8
diff --git a/lib/timeval.h b/lib/timeval.h
index 9217018a8..0df01192d 100644
--- a/lib/timeval.h
+++ b/lib/timeval.h
@@ -29,7 +29,12 @@
#include "curl_setup.h"
-struct timeval curlx_tvnow(void);
+struct curlval {
+ time_t tv_sec; /* seconds */
+ unsigned int tv_usec; /* microseconds */
+};
+
+struct curlval curlx_tvnow(void);
/*
* Make sure that the first argument (t1) is the more recent time and t2 is
@@ -37,7 +42,7 @@ struct timeval curlx_tvnow(void);
*
* Returns: the time difference in number of milliseconds.
*/
-time_t curlx_tvdiff(struct timeval t1, struct timeval t2);
+time_t curlx_tvdiff(struct curlval t1, struct curlval t2);
/*
* Make sure that the first argument (t1) is the more recent time and t2 is
@@ -45,7 +50,7 @@ time_t curlx_tvdiff(struct timeval t1, struct timeval t2);
*
* Returns: the time difference in number of microseconds.
*/
-time_t Curl_tvdiff_us(struct timeval newer, struct timeval older);
+time_t Curl_tvdiff_us(struct curlval newer, struct curlval older);
/* These two defines below exist to provide the older API for library
internals only. */
diff --git a/lib/url.c b/lib/url.c
index e4aa515be..9931688da 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -3275,7 +3275,7 @@ Curl_oldest_idle_connection(struct Curl_easy *data)
struct curl_hash_element *he;
time_t highscore=-1;
time_t score;
- struct timeval now;
+ struct curlval now;
struct connectdata *conn_candidate = NULL;
struct connectbundle *bundle;
@@ -3338,7 +3338,7 @@ find_oldest_idle_connection_in_bundle(struct Curl_easy *data,
struct curl_llist_element *curr;
time_t highscore=-1;
time_t score;
- struct timeval now;
+ struct curlval now;
struct connectdata *conn_candidate = NULL;
struct connectdata *conn;
@@ -3426,7 +3426,7 @@ static int call_disconnect_if_dead(struct connectdata *conn,
*/
static void prune_dead_connections(struct Curl_easy *data)
{
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
time_t elapsed = Curl_tvdiff(now, data->state.conn_cache->last_cleanup);
if(elapsed >= 1000L) {
diff --git a/lib/urldata.h b/lib/urldata.h
index 41f9408ba..64c4080ac 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -678,8 +678,8 @@ struct SingleRequest {
100 reply (without a following second response
code) result in a CURLE_GOT_NOTHING error code */
- struct timeval start; /* transfer started at this time */
- struct timeval now; /* current time */
+ struct curlval start; /* transfer started at this time */
+ struct curlval now; /* current time */
bool header; /* incoming data has HTTP header */
enum {
HEADER_NORMAL, /* no bad header at all */
@@ -701,7 +701,7 @@ struct SingleRequest {
Content-Range: header */
int httpcode; /* error code from the 'HTTP/1.? XXX' or
'RTSP/1.? XXX' line */
- struct timeval start100; /* time stamp to wait for the 100 code from */
+ struct curlval start100; /* time stamp to wait for the 100 code from */
enum expect100 exp100; /* expect 100 continue state */
enum upgrade101 upgr101; /* 101 upgrade state */
@@ -1016,8 +1016,8 @@ struct connectdata {
int httpversion; /* the HTTP version*10 reported by the server */
int rtspversion; /* the RTSP version*10 reported by the server */
- struct timeval now; /* "current" time */
- struct timeval created; /* creation time */
+ struct curlval now; /* "current" time */
+ struct curlval created; /* creation time */
curl_socket_t sock[2]; /* two sockets, the second is used for the data
transfer when doing FTP */
curl_socket_t tempsock[2]; /* temporary sockets for happy eyeballs */
@@ -1040,7 +1040,7 @@ struct connectdata {
/* connecttime: when connect() is called on the current IP address. Used to
be able to track when to move on to try next IP - but only when the multi
interface is used. */
- struct timeval connecttime;
+ struct curlval connecttime;
/* The two fields below get set in Curl_connecthost */
int num_addr; /* number of addresses to try to connect to */
time_t timeoutms_per_addr; /* how long time in milliseconds to spend on
@@ -1250,22 +1250,22 @@ struct Progress {
time_t t_starttransfer;
time_t t_redirect;
- struct timeval start;
- struct timeval t_startsingle;
- struct timeval t_startop;
- struct timeval t_acceptdata;
+ struct curlval start;
+ struct curlval t_startsingle;
+ struct curlval t_startop;
+ struct curlval t_acceptdata;
/* upload speed limit */
- struct timeval ul_limit_start;
+ struct curlval ul_limit_start;
curl_off_t ul_limit_size;
/* download speed limit */
- struct timeval dl_limit_start;
+ struct curlval dl_limit_start;
curl_off_t dl_limit_size;
#define CURR_TIME (5+1) /* 6 entries for 5 seconds */
curl_off_t speeder[ CURR_TIME ];
- struct timeval speeder_time[ CURR_TIME ];
+ struct curlval speeder_time[ CURR_TIME ];
int speeder_c;
};
@@ -1360,7 +1360,7 @@ typedef enum {
*/
struct time_node {
struct curl_llist_element list;
- struct timeval time;
+ struct curlval time;
expire_id eid;
};
@@ -1375,7 +1375,7 @@ struct UrlState {
bool multi_owned_by_easy;
/* buffers to store authentication data in, as parsed from input options */
- struct timeval keeps_speed; /* for the progress meter really */
+ struct curlval keeps_speed; /* for the progress meter really */
struct connectdata *lastconnect; /* The last connection, NULL if undefined */
@@ -1429,7 +1429,7 @@ struct UrlState {
#if defined(USE_OPENSSL) && defined(HAVE_OPENSSL_ENGINE_H)
ENGINE *engine;
#endif /* USE_OPENSSL */
- struct timeval expiretime; /* set this with Curl_expire() only */
+ struct curlval expiretime; /* set this with Curl_expire() only */
struct Curl_tree timenode; /* for the splay stuff */
struct curl_llist timeoutlist; /* list of pending timeouts */
struct time_node expires[EXPIRE_LAST]; /* nodes for each expire type */
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
index a77e4330e..c82193b61 100644
--- a/lib/vtls/openssl.c
+++ b/lib/vtls/openssl.c
@@ -290,16 +290,17 @@ static CURLcode Curl_ossl_seed(struct Curl_easy *data)
unsigned char randb[64];
size_t len = sizeof(randb);
size_t i, i_max;
- for(i = 0, i_max = len / sizeof(struct timeval); i < i_max; ++i) {
- struct timeval tv = curlx_tvnow();
+ for(i = 0, i_max = len / sizeof(struct curlval); i < i_max; ++i) {
+ struct curlval tv = curlx_tvnow();
Curl_wait_ms(1);
tv.tv_sec *= i + 1;
- tv.tv_usec *= i + 2;
+ tv.tv_usec *= (unsigned int)i + 2;
tv.tv_sec ^= ((curlx_tvnow().tv_sec + curlx_tvnow().tv_usec) *
(i + 3)) << 8;
- tv.tv_usec ^= ((curlx_tvnow().tv_sec + curlx_tvnow().tv_usec) *
- (i + 4)) << 16;
- memcpy(&randb[i * sizeof(struct timeval)], &tv, sizeof(struct timeval));
+ tv.tv_usec ^= (unsigned int) ((curlx_tvnow().tv_sec +
+ curlx_tvnow().tv_usec) *
+ (i + 4)) << 16;
+ memcpy(&randb[i * sizeof(struct curlval)], &tv, sizeof(struct curlval));
}
RAND_add(randb, (int)len, (double)len/2);
} while(!rand_enough());
diff --git a/tests/server/util.c b/tests/server/util.c
index a2340f462..c6d0cabdf 100644
--- a/tests/server/util.c
+++ b/tests/server/util.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -100,7 +100,7 @@ void logmsg(const char *msg, ...)
char buffer[2048 + 1];
FILE *logfp;
int error;
- struct timeval tv;
+ struct curlval tv;
time_t sec;
struct tm *now;
char timebuf[20];
@@ -211,9 +211,9 @@ int wait_ms(int timeout_ms)
{
#if !defined(MSDOS) && !defined(USE_WINSOCK)
#ifndef HAVE_POLL_FINE
- struct timeval pending_tv;
+ struct curlval pending_tv;
#endif
- struct timeval initial_tv;
+ struct curlval initial_tv;
int pending_ms;
int error;
#endif
diff --git a/tests/unit/unit1303.c b/tests/unit/unit1303.c
index 10206ff6b..f2d32015d 100644
--- a/tests/unit/unit1303.c
+++ b/tests/unit/unit1303.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -70,7 +70,7 @@ struct timetest {
UNITTEST_START
{
- struct timeval now;
+ struct curlval now;
time_t timeout;
unsigned int i;
diff --git a/tests/unit/unit1309.c b/tests/unit/unit1309.c
index 6cf886e9e..c1c599338 100644
--- a/tests/unit/unit1309.c
+++ b/tests/unit/unit1309.c
@@ -74,17 +74,19 @@ UNITTEST_START
struct Curl_tree nodes[NUM_NODES*3];
int rc;
int i, j;
- struct timeval tv_now = {0, 0};
+ struct curlval tv_now = {0, 0};
root = NULL; /* the empty tree */
/* add nodes */
for(i = 0; i < NUM_NODES; i++) {
- struct timeval key;
+ struct curlval key;
+ size_t payload;
key.tv_sec = 0;
key.tv_usec = (541*i)%1023;
+ payload = (size_t) key.tv_usec;
- nodes[i].payload = (void *)key.tv_usec; /* for simplicity */
+ nodes[i].payload = (void *)payload; /* for simplicity */
root = Curl_splayinsert(key, root, &nodes[i]);
}
@@ -109,14 +111,15 @@ UNITTEST_START
/* rebuild tree */
for(i = 0; i < NUM_NODES; i++) {
- struct timeval key;
+ struct curlval key;
key.tv_sec = 0;
key.tv_usec = (541*i)%1023;
/* add some nodes with the same key */
for(j = 0; j <= i % 3; j++) {
- nodes[i*3+j].payload = (void *)(key.tv_usec*10 + j); /* for simplicity */
+ size_t payload = key.tv_usec*10 + j;
+ nodes[i*3+j].payload = (void *)payload; /* for simplicity */
root = Curl_splayinsert(key, root, &nodes[i*3+j]);
}
}
diff --git a/tests/unit/unit1399.c b/tests/unit/unit1399.c
index d951504ea..cbc9004ac 100644
--- a/tests/unit/unit1399.c
+++ b/tests/unit/unit1399.c
@@ -48,7 +48,7 @@ static bool usec_matches_seconds(time_t time_usec, int expected_seconds)
UNITTEST_START
struct Curl_easy data;
- struct timeval now = Curl_tvnow();
+ struct curlval now = Curl_tvnow();
data.progress.t_starttransfer = 0;
data.progress.t_redirect = 0;
diff --git a/tests/unit/unit1606.c b/tests/unit/unit1606.c
index f08735b3f..e4941f381 100644
--- a/tests/unit/unit1606.c
+++ b/tests/unit/unit1606.c
@@ -41,7 +41,7 @@ static int runawhile(struct Curl_easy *easy,
int dec)
{
int counter = 1;
- struct timeval now = {1, 0};
+ struct curlval now = {1, 0};
CURLcode result;
int finaltime;