Switch server->connect_time from time_t to struct timeval

This means that settings like CONNECT_DELAY and CONNECT_TIMEOUT are compared
against the current time with sub-second resolution.  With the old way, the
delays could be up to a second longer than asked for, which had the effect of
almost doubling the default CONNECT_DELAY value of 1.
This commit is contained in:
Kevin Easton
2015-05-13 23:17:18 +10:00
parent 4ee6c6295b
commit f1c27a4f64
2 changed files with 6 additions and 7 deletions

View File

@@ -155,7 +155,7 @@ typedef struct
int from_server; int from_server;
#endif #endif
char *orignick; char *orignick;
time_t connect_time; struct timeval connect_time;
#if defined(HAVE_SSL) && !defined(IN_MODULE) #if defined(HAVE_SSL) && !defined(IN_MODULE)
SSL_CTX* ctx; SSL_CTX* ctx;
int enable_ssl; int enable_ssl;

View File

@@ -387,8 +387,7 @@ static void scan_nonblocking(void)
if (((server_list[i].read > -1) || if (((server_list[i].read > -1) ||
(server_list[i].write > -1)) && (server_list[i].write > -1)) &&
!(server_list[i].login_flags & LOGGED_IN) && !(server_list[i].login_flags & LOGGED_IN) &&
(time(NULL) - server_list[i].connect_time > time_since(&server_list[i].connect_time) > connect_timeout) {
connect_timeout)) {
if (server_list[i].read > -1) if (server_list[i].read > -1)
new_close(server_list[i].read); new_close(server_list[i].read);
if (server_list[i].write > -1) if (server_list[i].write > -1)
@@ -439,7 +438,7 @@ void do_idle_server (void)
{ {
int connect_delay = get_int_var(CONNECT_DELAY_VAR); int connect_delay = get_int_var(CONNECT_DELAY_VAR);
if(!connect_delay || (time(NULL) - server_list[i].connect_time) > connect_delay) if (time_since(&server_list[i].connect_time) > connect_delay)
{ {
int servernum = i; int servernum = i;
@@ -479,7 +478,7 @@ static time_t last_timeout = 0;
{ {
int connect_delay = get_int_var(CONNECT_DELAY_VAR); int connect_delay = get_int_var(CONNECT_DELAY_VAR);
if(!connect_delay || (time(NULL) - server_list[i].connect_time) > connect_delay) if (time_since(&server_list[i].connect_time) > connect_delay)
{ {
int servernum = i; int servernum = i;
@@ -1417,7 +1416,7 @@ int BX_connect_to_server_by_refnum (int refnum, int c_server)
if (conn) if (conn)
return -1; return -1;
server_list[refnum].connect_time = time(NULL); get_time(&server_list[refnum].connect_time);
#ifdef NON_BLOCKING_CONNECTS #ifdef NON_BLOCKING_CONNECTS
server_list[refnum].connect_wait = 1; server_list[refnum].connect_wait = 1;
server_list[refnum].c_server = c_server; server_list[refnum].c_server = c_server;
@@ -3331,7 +3330,7 @@ void set_server_reconnect(int s, int val)
{ {
server_list[s].reconnect = val; server_list[s].reconnect = val;
if(val) if(val)
server_list[s].connect_time = time(NULL); get_time(&server_list[s].connect_time);
} }
} }