time: rename Curl_tvnow to Curl_now

... since the 'tv' stood for timeval and this function does not return a
timeval struct anymore.

Also, cleaned up the Curl_timediff*() functions to avoid typecasts and
clean up the descriptive comments.

Closes #2011
This commit is contained in:
Daniel Stenberg 2017-10-25 11:59:43 +02:00
parent 1d72b5b891
commit 5d543fe906
23 changed files with 73 additions and 83 deletions

View File

@ -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 curltime now = Curl_tvnow();
struct curltime now = Curl_now();
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 curltime now2 = Curl_tvnow();
struct curltime now2 = Curl_now();
timediff_t timediff = Curl_timediff(now2, now); /* spent time */
if(timediff <= 0)
timeout -= 1; /* always deduct at least 1 */

View File

@ -535,7 +535,7 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
}
else {
/* poll for name lookup done with exponential backoff up to 250ms */
timediff_t elapsed = Curl_timediff(Curl_tvnow(),
timediff_t elapsed = Curl_timediff(Curl_now(),
data->progress.t_startsingle);
if(elapsed < 0)
elapsed = 0;

View File

@ -218,7 +218,7 @@ time_t Curl_timeleft(struct Curl_easy *data,
}
if(!nowp) {
now = Curl_tvnow();
now = Curl_now();
nowp = &now;
}
@ -737,7 +737,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
return CURLE_OK;
}
now = Curl_tvnow();
now = Curl_now();
/* figure out how long time we have left to connect */
allow = Curl_timeleft(data, &now, TRUE);
@ -1051,7 +1051,7 @@ static CURLcode singleipconnect(struct connectdata *conn,
/* set socket non-blocking */
(void)curlx_nonblock(sockfd, TRUE);
conn->connecttime = Curl_tvnow();
conn->connecttime = Curl_now();
if(conn->num_addr > 1)
Curl_expire(data, conn->timeoutms_per_addr, EXPIRE_DNS_PER_NAME);
@ -1145,7 +1145,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
const struct Curl_dns_entry *remotehost)
{
struct Curl_easy *data = conn->data;
struct curltime before = Curl_tvnow();
struct curltime before = Curl_now();
CURLcode result = CURLE_COULDNT_CONNECT;
time_t timeout_ms = Curl_timeleft(data, &before, TRUE);

View File

@ -586,12 +586,12 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
}
/* get the time stamp to use to figure out how long poll takes */
before = Curl_tvnow();
before = Curl_now();
/* wait for activity or timeout */
pollrc = Curl_poll(fds, numfds, (int)ev->ms);
after = Curl_tvnow();
after = Curl_now();
ev->msbump = FALSE; /* reset here */
@ -680,12 +680,12 @@ static CURLcode easy_transfer(struct Curl_multi *multi)
int still_running = 0;
int rc;
before = Curl_tvnow();
before = Curl_now();
mcode = curl_multi_wait(multi, NULL, 0, 1000, &rc);
if(!mcode) {
if(!rc) {
struct curltime after = Curl_tvnow();
struct curltime after = Curl_now();
/* If it returns without any filedescriptor instantly, we need to
avoid busy-looping during periods where it has nothing particular

View File

@ -404,7 +404,7 @@ static CURLcode file_upload(struct connectdata *conn)
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
result = Curl_speedcheck(data, Curl_tvnow());
result = Curl_speedcheck(data, Curl_now());
}
if(!result && Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
@ -589,7 +589,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
result = Curl_speedcheck(data, Curl_tvnow());
result = Curl_speedcheck(data, Curl_now());
}
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;

View File

@ -341,7 +341,7 @@ static time_t ftp_timeleft_accept(struct Curl_easy *data)
if(data->set.accepttimeout > 0)
timeout_ms = data->set.accepttimeout;
now = Curl_tvnow();
now = Curl_now();
/* check if the generic timeout possibly is set shorter */
other = Curl_timeleft(data, &now, FALSE);
@ -3261,7 +3261,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
long old_time = pp->response_time;
pp->response_time = 60*1000; /* give it only a minute for now */
pp->response = Curl_tvnow(); /* timeout relative now */
pp->response = Curl_now(); /* timeout relative now */
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
@ -3381,7 +3381,7 @@ CURLcode ftp_sendquote(struct connectdata *conn, struct curl_slist *quote)
PPSENDF(&conn->proto.ftpc.pp, "%s", cmd);
pp->response = Curl_tvnow(); /* timeout relative now */
pp->response = Curl_now(); /* timeout relative now */
result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if(result)

View File

@ -688,7 +688,7 @@ clean_up:
the time we spent until now! */
if(prev_alarm) {
/* there was an alarm() set before us, now put it back */
timediff_t elapsed_secs = Curl_timediff(Curl_tvnow(),
timediff_t elapsed_secs = Curl_timediff(Curl_now(),
conn->created) / 1000;
/* the alarm period is counted in even number of seconds */

View File

@ -2147,7 +2147,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 curltime now = Curl_tvnow();
struct curltime now = Curl_now();
if(!GOOD_MULTI_HANDLE(multi))
return CURLM_BAD_HANDLE;
@ -2553,7 +2553,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
CURLMcode result = CURLM_OK;
struct Curl_easy *data = NULL;
struct Curl_tree *t;
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
if(checkall) {
/* *perform() deals with running_handles on its own */
@ -2629,8 +2629,8 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
data = NULL; /* set data to NULL again to avoid calling
multi_runsingle() in case there's no need to */
now = Curl_tvnow(); /* get a newer time since the multi_runsingle() loop
may have taken some time */
now = Curl_now(); /* get a newer time since the multi_runsingle() loop
may have taken some time */
}
}
else {
@ -2783,7 +2783,7 @@ static CURLMcode multi_timeout(struct Curl_multi *multi,
if(multi->timetree) {
/* we have a tree of expire times */
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
/* splay the lowest to the bottom */
multi->timetree = Curl_splay(tv_zero, multi->timetree);
@ -2949,7 +2949,7 @@ void Curl_expire(struct Curl_easy *data, time_t milli, expire_id id)
DEBUGASSERT(id < EXPIRE_LAST);
set = Curl_tvnow();
set = Curl_now();
set.tv_sec += milli/1000;
set.tv_usec += (unsigned int)(milli%1000)*1000;

View File

@ -61,12 +61,12 @@ time_t Curl_pp_state_timeout(struct pingpong *pp)
/* Without a requested timeout, we only wait 'response_time' seconds for the
full response to arrive before we bail out */
timeout_ms = response_time -
Curl_timediff(Curl_tvnow(), pp->response); /* spent time */
Curl_timediff(Curl_now(), pp->response); /* spent time */
if(data->set.timeout) {
/* if timeout is requested, find out how much remaining time we have */
timeout2_ms = data->set.timeout - /* timeout time */
Curl_timediff(Curl_tvnow(), conn->now); /* spent time */
Curl_timediff(Curl_now(), conn->now); /* spent time */
/* pick the lowest number */
timeout_ms = CURLMIN(timeout_ms, timeout2_ms);
@ -120,7 +120,7 @@ CURLcode Curl_pp_statemach(struct pingpong *pp, bool block)
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
result = Curl_speedcheck(data, Curl_tvnow());
result = Curl_speedcheck(data, Curl_now());
if(result)
return result;
@ -143,7 +143,7 @@ void Curl_pp_init(struct pingpong *pp)
pp->nread_resp = 0;
pp->linestart_resp = conn->data->state.buffer;
pp->pending_resp = TRUE;
pp->response = Curl_tvnow(); /* start response time-out now! */
pp->response = Curl_now(); /* start response time-out now! */
}
@ -235,7 +235,7 @@ CURLcode Curl_pp_vsendf(struct pingpong *pp,
free(s);
pp->sendthis = NULL;
pp->sendleft = pp->sendsize = 0;
pp->response = Curl_tvnow();
pp->response = Curl_now();
}
return CURLE_OK;
@ -499,7 +499,7 @@ CURLcode Curl_pp_flushsend(struct pingpong *pp)
free(pp->sendthis);
pp->sendthis = NULL;
pp->sendleft = pp->sendsize = 0;
pp->response = Curl_tvnow();
pp->response = Curl_now();
}
return CURLE_OK;
}

View File

@ -58,8 +58,8 @@ 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 curltime response; /* set to Curl_tvnow() when a command has been sent
off, used to time-out response reading */
struct curltime response; /* set to Curl_now() 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. */

View File

@ -161,7 +161,7 @@ void Curl_pgrsResetTransferSizes(struct Curl_easy *data)
*/
void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
{
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
time_t *delta = NULL;
switch(timer) {
@ -226,7 +226,7 @@ void Curl_pgrsTime(struct Curl_easy *data, timerid timer)
void Curl_pgrsStartNow(struct Curl_easy *data)
{
data->progress.speeder_c = 0; /* reset the progress meter display */
data->progress.start = Curl_tvnow();
data->progress.start = Curl_now();
data->progress.is_t_startransfer_set = false;
data->progress.ul_limit_start.tv_sec = 0;
data->progress.ul_limit_start.tv_usec = 0;
@ -285,7 +285,7 @@ long Curl_pgrsLimitWaitTime(curl_off_t cursize,
void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
{
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
data->progress.downloaded = size;
@ -303,7 +303,7 @@ void Curl_pgrsSetDownloadCounter(struct Curl_easy *data, curl_off_t size)
void Curl_pgrsSetUploadCounter(struct Curl_easy *data, curl_off_t size)
{
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
data->progress.uploaded = size;
@ -370,7 +370,7 @@ int Curl_pgrsUpdate(struct connectdata *conn)
curl_off_t total_estimate;
bool shownow = FALSE;
now = Curl_tvnow(); /* what time is it */
now = Curl_now(); /* what time is it */
/* The time spent so far (from the start) */
data->progress.timespent = Curl_timediff_us(now, data->progress.start);

View File

@ -86,7 +86,7 @@ static CURLcode randit(struct Curl_easy *data, unsigned int *rnd)
#endif
if(!seeded) {
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
infof(data, "WARNING: Using weak random seed\n");
randseed += (unsigned int)now.tv_usec + (unsigned int)now.tv_sec;
randseed = randseed * 1103515245 + 12345;

View File

@ -51,7 +51,7 @@
#include "warnless.h"
/* Convenience local macros */
#define ELAPSED_MS() (int)Curl_timediff(Curl_tvnow(), initial_tv)
#define ELAPSED_MS() (int)Curl_timediff(Curl_now(), initial_tv)
int Curl_ack_eintr = 0;
#define ERROR_NOT_EINTR(error) (Curl_ack_eintr || error != EINTR)
@ -96,7 +96,7 @@ int Curl_wait_ms(int timeout_ms)
Sleep(timeout_ms);
#else
pending_ms = timeout_ms;
initial_tv = Curl_tvnow();
initial_tv = Curl_now();
do {
#if defined(HAVE_POLL_FINE)
r = poll(NULL, 0, pending_ms);
@ -184,7 +184,7 @@ int Curl_socket_check(curl_socket_t readfd0, /* two sockets to read from */
if(timeout_ms > 0) {
pending_ms = (int)timeout_ms;
initial_tv = Curl_tvnow();
initial_tv = Curl_now();
}
#ifdef HAVE_POLL_FINE
@ -425,7 +425,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
if(timeout_ms > 0) {
pending_ms = timeout_ms;
initial_tv = Curl_tvnow();
initial_tv = Curl_now();
}
#ifdef HAVE_POLL_FINE

View File

@ -1233,7 +1233,7 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
}
else {
/* Successfully sent so adjust the response timeout relative to now */
pp->response = Curl_tvnow();
pp->response = Curl_now();
free(eob);
}

View File

@ -2834,7 +2834,7 @@ static CURLcode ssh_block_statemach(struct connectdata *conn,
while((sshc->state != SSH_STOP) && !result) {
bool block;
time_t left = 1000;
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
result = ssh_statemach_act(conn, &block);
if(result)

View File

@ -1560,7 +1560,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
}
if(data->set.timeout) {
now = Curl_tvnow();
now = Curl_now();
if(Curl_timediff(now, conn->created) >= data->set.timeout) {
failf(data, "Time-out");
result = CURLE_OPERATION_TIMEDOUT;
@ -1678,7 +1678,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
} /* poll switch statement */
if(data->set.timeout) {
now = Curl_tvnow();
now = Curl_now();
if(Curl_timediff(now, conn->created) >= data->set.timeout) {
failf(data, "Time-out");
result = CURLE_OPERATION_TIMEDOUT;

View File

@ -1293,7 +1293,7 @@ static CURLcode tftp_doing(struct connectdata *conn, bool *dophase_done)
if(Curl_pgrsUpdate(conn))
result = CURLE_ABORTED_BY_CALLBACK;
else
result = Curl_speedcheck(conn->data, Curl_tvnow());
result = Curl_speedcheck(conn->data, Curl_now());
}
return result;
}

View File

@ -24,7 +24,7 @@
#if defined(WIN32) && !defined(MSDOS)
struct curltime Curl_tvnow(void)
struct curltime Curl_now(void)
{
/*
** GetTickCount() is available on _all_ Windows versions from W95 up
@ -48,7 +48,7 @@ struct curltime Curl_tvnow(void)
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
struct curltime Curl_tvnow(void)
struct curltime Curl_now(void)
{
/*
** clock_gettime() is granted to be increased monotonically when the
@ -86,7 +86,7 @@ struct curltime Curl_tvnow(void)
#elif defined(HAVE_GETTIMEOFDAY)
struct curltime Curl_tvnow(void)
struct curltime Curl_now(void)
{
/*
** gettimeofday() is not granted to be increased monotonically, due to
@ -103,7 +103,7 @@ struct curltime Curl_tvnow(void)
#else
struct curltime Curl_tvnow(void)
struct curltime Curl_now(void)
{
/*
** time() returns the value of time in seconds since the Epoch.
@ -125,11 +125,8 @@ struct curltime Curl_tvnow(void)
#endif
/*
* Make sure that the first argument is the more recent time, as otherwise
* we'll get a weird negative time-diff back...
*
* Returns: the time difference in number of milliseconds. For large diffs it
* returns 0x7fffffff on 32bit time_t systems.
* Returns: time difference in number of milliseconds. For too large diffs it
* returns max value.
*
* @unittest: 1323
*/
@ -140,16 +137,12 @@ timediff_t Curl_timediff(struct curltime newer, struct curltime older)
return TIME_MAX;
else if(diff <= (TIME_MIN/1000))
return TIME_MIN;
return (timediff_t)(newer.tv_sec-older.tv_sec)*1000+
(timediff_t)(newer.tv_usec-older.tv_usec)/1000;
return diff * 1000 + (newer.tv_usec-older.tv_usec)/1000;
}
/*
* Make sure that the first argument is the more recent time, as otherwise
* we'll get a weird negative time-diff back...
*
* Returns: the time difference in number of microseconds. For too large diffs
* it returns max value.
* Returns: time difference in number of microseconds. For too large diffs it
* returns max value.
*/
timediff_t Curl_timediff_us(struct curltime newer, struct curltime older)
{
@ -158,6 +151,5 @@ timediff_t Curl_timediff_us(struct curltime newer, struct curltime older)
return TIME_MAX;
else if(diff <= (TIME_MIN/1000000))
return TIME_MIN;
return (timediff_t)(newer.tv_sec-older.tv_sec)*1000000+
(timediff_t)(newer.tv_usec-older.tv_usec);
return diff * 1000000 + newer.tv_usec-older.tv_usec;
}

View File

@ -30,13 +30,12 @@ typedef int timediff_t;
typedef ssize_t timediff_t;
#endif
struct curltime {
time_t tv_sec; /* seconds */
int tv_usec; /* microseconds */
};
struct curltime Curl_tvnow(void);
struct curltime Curl_now(void);
/*
* Make sure that the first argument (t1) is the more recent time and t2 is
@ -55,4 +54,3 @@ timediff_t Curl_timediff(struct curltime t1, struct curltime t2);
timediff_t Curl_timediff_us(struct curltime newer, struct curltime older);
#endif /* HEADER_CURL_TIMEVAL_H */

View File

@ -490,7 +490,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
Curl_pgrsTime(data, TIMER_STARTTRANSFER);
if(k->exp100 > EXP100_SEND_DATA)
/* set time stamp to compare with when waiting for the 100 */
k->start100 = Curl_tvnow();
k->start100 = Curl_now();
}
*didwhat |= KEEP_RECV;
@ -925,7 +925,7 @@ static CURLcode readwrite_upload(struct Curl_easy *data,
go into the Expect: 100 state and await such a header */
k->exp100 = EXP100_AWAITING_CONTINUE; /* wait for the header */
k->keepon &= ~KEEP_SEND; /* disable writing */
k->start100 = Curl_tvnow(); /* timeout count starts now */
k->start100 = Curl_now(); /* timeout count starts now */
*didwhat &= ~KEEP_SEND; /* we didn't write anything actually */
/* set a timeout for the multi interface */
@ -1150,7 +1150,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
return result;
}
k->now = Curl_tvnow();
k->now = Curl_now();
if(didwhat) {
/* Update read/write counters */
if(k->bytecountp)
@ -2050,7 +2050,7 @@ Curl_setup_transfer(
(http->sending == HTTPSEND_BODY)) {
/* wait with write until we either got 100-continue or a timeout */
k->exp100 = EXP100_AWAITING_CONTINUE;
k->start100 = Curl_tvnow();
k->start100 = Curl_now();
/* Set a timeout for the multi interface. Add the inaccuracy margin so
that we don't fire slightly too early and get denied to run. */

View File

@ -3465,7 +3465,7 @@ Curl_oldest_idle_connection(struct Curl_easy *data)
struct connectdata *conn_candidate = NULL;
struct connectbundle *bundle;
now = Curl_tvnow();
now = Curl_now();
Curl_hash_start_iterate(&bc->hash, &iter);
@ -3530,7 +3530,7 @@ find_oldest_idle_connection_in_bundle(struct Curl_easy *data,
(void)data;
now = Curl_tvnow();
now = Curl_now();
curr = bundle->conn_list.head;
while(curr) {
@ -3612,7 +3612,7 @@ static int call_disconnect_if_dead(struct connectdata *conn,
*/
static void prune_dead_connections(struct Curl_easy *data)
{
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
time_t elapsed = Curl_timediff(now, data->state.conn_cache->last_cleanup);
if(elapsed >= 1000L) {
@ -4385,7 +4385,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
connclose(conn, "Default to force-close");
/* Store creation time to help future close decision making */
conn->created = Curl_tvnow();
conn->created = Curl_now();
conn->data = data; /* Setup the association between this connection
and the Curl_easy */
@ -7128,7 +7128,7 @@ CURLcode Curl_setup_conn(struct connectdata *conn,
/* set start time here for timeout purposes in the connect procedure, it
is later set again for the progress meter purpose */
conn->now = Curl_tvnow();
conn->now = Curl_now();
if(CURL_SOCKET_BAD == conn->sock[FIRSTSOCKET]) {
conn->bits.tcpconnect[FIRSTSOCKET] = FALSE;
@ -7145,7 +7145,7 @@ CURLcode Curl_setup_conn(struct connectdata *conn,
Curl_verboseconnect(conn);
}
conn->now = Curl_tvnow(); /* time this *after* the connect is done, we
conn->now = Curl_now(); /* time this *after* the connect is done, we
set this here perhaps a second time */
#ifdef __EMX__
@ -7236,7 +7236,7 @@ CURLcode Curl_init_do(struct Curl_easy *data, struct connectdata *conn)
HTTP. */
data->set.httpreq = HTTPREQ_GET;
k->start = Curl_tvnow(); /* start time */
k->start = Curl_now(); /* start time */
k->now = k->start; /* current time is now */
k->header = TRUE; /* assume header */

View File

@ -446,14 +446,14 @@ static CURLcode Curl_ossl_seed(struct Curl_easy *data)
size_t len = sizeof(randb);
size_t i, i_max;
for(i = 0, i_max = len / sizeof(struct curltime); i < i_max; ++i) {
struct curltime tv = Curl_tvnow();
struct curltime tv = Curl_now();
Curl_wait_ms(1);
tv.tv_sec *= i + 1;
tv.tv_usec *= (unsigned int)i + 2;
tv.tv_sec ^= ((Curl_tvnow().tv_sec + Curl_tvnow().tv_usec) *
tv.tv_sec ^= ((Curl_now().tv_sec + Curl_now().tv_usec) *
(i + 3)) << 8;
tv.tv_usec ^= (unsigned int) ((Curl_tvnow().tv_sec +
Curl_tvnow().tv_usec) *
tv.tv_usec ^= (unsigned int) ((Curl_now().tv_sec +
Curl_now().tv_usec) *
(i + 4)) << 16;
memcpy(&randb[i * sizeof(struct curltime)], &tv,
sizeof(struct curltime));

View File

@ -80,7 +80,7 @@ static void expect_timer_seconds(struct Curl_easy *data, int seconds)
* be 3 seconds. */
UNITTEST_START
struct Curl_easy data;
struct curltime now = Curl_tvnow();
struct curltime now = Curl_now();
data.progress.t_nslookup = 0;
data.progress.t_connect = 0;