Rework the calculation of the select timeout in io() to be based on absolute wake time

An absolute wake time is now calculated and updated by set_server_bits(),
TimerTimeout() and tclTimerTimeout().  This is then used to calculate the actual
select() timeout, instead of having those functions calculate a relative timeout
value themselves.  This significantly simplifies those functions, since the
underlying values tend to be recorded as absolute times.

It also allows us to disentangle tclTimeTimeout from TimerTimeout(), and move the
responsibility for calculating the QUEUE_SENDS wake time from TimerTimeout() to
set_server_bits() where it belongs.

The QUEUE_SENDS and CONNECT_DELAY wake up times will also now be correctly
calculated, based on the last sent time and connect time respectively.
This commit is contained in:
Kevin Easton
2015-06-07 00:03:09 +10:00
parent 6f0f9dd8a8
commit c0c7cdbdcc
7 changed files with 67 additions and 99 deletions

View File

@@ -1480,46 +1480,24 @@ long time_left;
}
}
static struct timeval current;
time_t tclTimerTimeout(time_t timeout)
void tclTimerTimeout(struct timeval *wake_time)
{
register TimerList *stack = NULL;
long this_timeout = 0;
TimerList *stack = NULL;
if (timeout == 0)
return 0;
get_time(&current);
if ((stack = tcl_Pending_timers))
{
/* this is in minutes */
for (; stack; stack = stack->next)
if ((this_timeout = (BX_time_diff(current, stack->time)) * 1000) < timeout)
timeout = this_timeout;
}
if ((stack = tcl_Pending_utimers))
{
/* this is in seconds */
for (; stack; stack = stack->next)
if ((this_timeout = (BX_time_diff(current, stack->time)) * 1000) < timeout)
timeout = this_timeout;
}
#if defined(WINNT) || defined(__EMX__)
return (timeout == MAGIC_TIMEOUT) ? MAGIC_TIMEOUT : timeout;
#else
return timeout;
#endif
/* this is in minutes */
for (stack = tcl_Pending_timers; stack; stack = stack->next)
if (time_cmp(wake_time, &stack->time) > 0)
*wake_time = stack->time;
/* this is in seconds */
for (stack = tcl_Pending_utimers; stack; stack = stack->next)
if (time_cmp(wake_time, &stack->time) > 0)
*wake_time = stack->time;
}
#else /* WANT_TCL */
time_t tclTimerTimeout(time_t timeout)
void tclTimerTimeout(struct timeval *wake_time)
{
#if defined(WINNT) || defined(__EMX__)
return (timeout == MAGIC_TIMEOUT) ? MAGIC_TIMEOUT : timeout;
#else
return timeout < MAGIC_TIMEOUT ? timeout : MAGIC_TIMEOUT;
#endif
}
int check_tcl_dcc(char *cmd, char *nick, char *host, int idx)