Fix fd leak. Delay reconnections.

This commit is contained in:
nohar 2007-02-10 14:05:37 +00:00
parent fd87c58cef
commit 458abaf452
4 changed files with 27 additions and 10 deletions

View File

@ -1,3 +1,8 @@
2007-01-01 Arnaud Cornet <arnaud.cornet@gmail.com>
* src/connection.c: Fix fd leak.
* src/irc.c: Delay reconnections.
2007-02-26 Arnaud Cornet <arnaud.cornet@gmail.com> 2007-02-26 Arnaud Cornet <arnaud.cornet@gmail.com>
* *: Merge a patch from Trou for .oidentd.conf not to be overwritten. * *: Merge a patch from Trou for .oidentd.conf not to be overwritten.

View File

@ -98,10 +98,6 @@ void connection_free(connection_t *cn)
free(cn); free(cn);
} }
/* XXX
* m'expliquer le local bind
* API Suxor
*/
static void connect_trynext(connection_t *cn) static void connect_trynext(connection_t *cn)
{ {
struct addrinfo *cur; struct addrinfo *cur;
@ -634,8 +630,11 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc)
if (err2 < 0) { if (err2 < 0) {
mylog(LOG_DEBUGVERB, "fd:%d getsockopt error: %s", mylog(LOG_DEBUGVERB, "fd:%d getsockopt error: %s",
cn->handle, strerror(errno)); cn->handle, strerror(errno));
if (cn->connecting_data) if (cn->connecting_data) {
close(cn->handle);
cn->handle = -1;
connect_trynext(cn); connect_trynext(cn);
}
return (cn_is_new(cn) || cn->connected == return (cn_is_new(cn) || cn->connected ==
CONN_NEED_SSLIZE) ? 0 : 1; CONN_NEED_SSLIZE) ? 0 : 1;
@ -658,8 +657,11 @@ static int check_event_write(fd_set *fds, connection_t *cn, int *nc)
} else { } else {
mylog(LOG_WARN, "fd:%d Socket error: %s", cn->handle, mylog(LOG_WARN, "fd:%d Socket error: %s", cn->handle,
strerror(err)); strerror(err));
if (cn->connecting_data) if (cn->connecting_data) {
close(cn->handle);
cn->handle = -1;
connect_trynext(cn); connect_trynext(cn);
}
return (cn_is_new(cn) || cn->connected == return (cn_is_new(cn) || cn->connected ==
CONN_NEED_SSLIZE) ? 0 : 1; CONN_NEED_SSLIZE) ? 0 : 1;
} }
@ -1057,7 +1059,7 @@ connection_t *listen_new(char *hostname, int port, int ssl)
/* TODO: allow litteral service name in the function interface */ /* TODO: allow litteral service name in the function interface */
if (snprintf(portbuf, 20, "%d", port) >= 20) if (snprintf(portbuf, 20, "%d", port) >= 20)
portbuf[19] = '\0'; portbuf[19] = '\0';
/* /*
* SSL flag is only here to tell program to convert socket to SSL after * SSL flag is only here to tell program to convert socket to SSL after
* accept(). Listening socket will NOT be SSL * accept(). Listening socket will NOT be SSL
@ -1408,9 +1410,11 @@ static int connection_timedout(connection_t *cn)
if (!cn->connecting_data) if (!cn->connecting_data)
fatal("connection_timedout called with no connecting_data!\n"); fatal("connection_timedout called with no connecting_data!\n");
if (time(NULL)-cn->connect_time > cn->timeout) { if (time(NULL) - cn->connect_time > cn->timeout) {
/* connect() completion timed out */ /* connect() completion timed out */
close(cn->handle);
cn->handle = -1;
connect_trynext(cn); connect_trynext(cn);
if (!cn_is_new(cn) && cn->connected != CONN_NEED_SSLIZE) if (!cn_is_new(cn) && cn->connected != CONN_NEED_SSLIZE)
return 1; return 1;

View File

@ -214,6 +214,11 @@ static void irc_server_connected(struct link_server *server)
{ {
int i; int i;
LINK(server)->s_state = IRCS_CONNECTED; LINK(server)->s_state = IRCS_CONNECTED;
LINK(server)->s_conn_attempt = 0;
mylog(LOG_INFO, "Connected user %s to %s", LINK(server)->username,
LINK(server)->name);
irc_server_join(server); irc_server_join(server);
log_connected(LINK(server)->log); log_connected(LINK(server)->log);
@ -1902,6 +1907,8 @@ static void irc_close(struct link_any *l)
if (LINK(is)->s_state == IRCS_CONNECTED) if (LINK(is)->s_state == IRCS_CONNECTED)
irc_notify_disconnection(is); irc_notify_disconnection(is);
else
LINK(is)->s_conn_attempt++;
irc_server_shutdown(is); irc_server_shutdown(is);
log_disconnected(LINK(is)->log); log_disconnected(LINK(is)->log);
@ -1910,7 +1917,7 @@ static void irc_close(struct link_any *l)
if (LINK(is)->last_connection && if (LINK(is)->last_connection &&
time(NULL) - LINK(is)->last_connection time(NULL) - LINK(is)->last_connection
< CONN_INTERVAL) < CONN_INTERVAL)
timer = RECONN_TIMER; timer = RECONN_TIMER * (LINK(is)->s_conn_attempt);
mylog(LOG_ERROR, "%s dead, reconnecting in %d seconds", mylog(LOG_ERROR, "%s dead, reconnecting in %d seconds",
LINK(l)->name, timer); LINK(l)->name, timer);
LINK(is)->recon_timer = timer; LINK(is)->recon_timer = timer;

View File

@ -78,6 +78,7 @@ struct link {
/* server related live stuff */ /* server related live stuff */
int s_state; int s_state;
int s_conn_attempt;
char *prev_nick; /* XXX del me */ char *prev_nick; /* XXX del me */
char *cli_nick; char *cli_nick;
list_t init_strings; list_t init_strings;