Add time_until() and time_since() utility functions
Adding these in preparation for converting server->connect_time from time_t to struct timeval. Also converts three existing open-coded versions over to the new functions.
This commit is contained in:
@@ -84,6 +84,8 @@ int lw_strcmp (comp_func *, char *, char *);
|
||||
int open_to (char *, int, off_t);
|
||||
struct timeval BX_get_time (struct timeval *);
|
||||
double BX_time_diff (struct timeval, struct timeval);
|
||||
double time_since(const struct timeval *tv_from);
|
||||
double time_until(const struct timeval *tv_to);
|
||||
char * BX_plural (int);
|
||||
int BX_time_to_next_minute (void);
|
||||
char * BX_remove_trailing_spaces (char *);
|
||||
|
||||
@@ -5531,7 +5531,7 @@ struct timeval start;
|
||||
* with the arguments.
|
||||
*/
|
||||
add_timer(0, empty_string, milliseconds, 1, (int (*)(void *, char *))comment, NULL, NULL, get_current_winref(), "pause");
|
||||
while (BX_time_diff(get_time(NULL), start) > 0)
|
||||
while (time_until(&start) > 0)
|
||||
io("e_pause");
|
||||
}
|
||||
|
||||
|
||||
@@ -1617,7 +1617,7 @@ char lame_type[30];
|
||||
strcpy(lame_type, "T");
|
||||
strcat(lame_type, dcc_types[type]->name);
|
||||
|
||||
xtime = BX_time_diff(n->starttime, get_time(NULL));
|
||||
xtime = time_since(&n->starttime);
|
||||
xfer = (double)(n->bytes_sent ? n->bytes_sent : n->bytes_read);
|
||||
|
||||
if (xfer == 0.0)
|
||||
@@ -2884,7 +2884,7 @@ DCC_int *n;
|
||||
return;
|
||||
dcc_bytes_in += n->bytes_read;
|
||||
dcc_bytes_out += n->bytes_sent;
|
||||
xtime = BX_time_diff(n->starttime, get_time(NULL));
|
||||
xtime = time_since(&n->starttime);
|
||||
|
||||
if (xtime <= 0)
|
||||
xtime = 1;
|
||||
|
||||
@@ -1746,6 +1746,24 @@ double BX_time_diff (struct timeval one, struct timeval two)
|
||||
return (double)td.tv_sec + ((double)td.tv_usec / 1000000.0);
|
||||
}
|
||||
|
||||
/* Calculate time elapsed since a time in the past. */
|
||||
double time_since(const struct timeval *tv_from)
|
||||
{
|
||||
struct timeval tv_now;
|
||||
|
||||
get_time(&tv_now);
|
||||
return BX_time_diff(*tv_from, tv_now);
|
||||
}
|
||||
|
||||
/* Calculate time from now until a time in the future. */
|
||||
double time_until(const struct timeval *tv_to)
|
||||
{
|
||||
struct timeval tv_now;
|
||||
|
||||
get_time(&tv_now);
|
||||
return BX_time_diff(tv_now, *tv_to);
|
||||
}
|
||||
|
||||
int BX_time_to_next_minute (void)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
|
||||
Reference in New Issue
Block a user