From 1bd9a2aa072be23bc4e8f976a110b9b4cee73376 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Sun, 1 May 2005 01:48:12 +0000 Subject: [PATCH] Fix several bugs in iauth code. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1391 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ChangeLog | 10 ++++++++++ ircd/ircd_auth.c | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 94cbea4..de627dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-04-30 Michael Poole + + * ircd/ircd_auth.c (iauth_connect): Initialize (but do not add) + timer here and set fd to -1. + (iauth_schedule_reconnect): Rewrite to handle previously + initialized timer. + (iauth_reconnect): If server is connected, disconnect first. + Update socket generator fd before calling socket_add(). + (iauth_read): When reading 0 bytes (EOF), reconnect. + 2005-04-27 Michael Poole * ircd/ircd_parser.y: Report non-existent class names as errors diff --git a/ircd/ircd_auth.c b/ircd/ircd_auth.c index 7487fd5..e944162 100644 --- a/ircd/ircd_auth.c +++ b/ircd/ircd_auth.c @@ -243,7 +243,9 @@ struct IAuth *iauth_connect(char *host, unsigned short port, char *passwd, time_ memset(&i_addr(iauth), 0, sizeof(i_addr(iauth))); i_port(iauth) = port; iauth_active = iauth; + timer_init(&i_reconn_timer(iauth)); i_reconnect(iauth) = reconnect; + s_fd(&i_socket(iauth)) = -1; iauth_reconnect(iauth); } if (passwd) @@ -435,9 +437,12 @@ static void iauth_reconnect_ev(struct Event *ev) static void iauth_schedule_reconnect(struct IAuth *iauth) { struct Timer *timer; - assert(!t_active(&i_reconn_timer(iauth))); - timer = timer_init(&i_reconn_timer(iauth)); - timer_add(timer, iauth_reconnect_ev, iauth, TT_RELATIVE, i_reconnect(iauth)); + timer = &i_reconn_timer(iauth); + if (t_onqueue(timer)) + timer_chg(timer, TT_RELATIVE, i_reconnect(iauth)); + else + timer_add(&i_reconn_timer(iauth), iauth_reconnect_ev, + iauth, TT_RELATIVE, i_reconnect(iauth)); } /** Initiate a (re-)connection to \a iauth. @@ -449,6 +454,8 @@ static void iauth_reconnect(struct IAuth *iauth) IOResult result; int fd; + if (s_fd(&i_socket(iauth)) != -1) + iauth_disconnect(iauth); Debug((DEBUG_INFO, "IAuth attempt connection to %s port %p.", i_host(iauth), i_port(iauth))); if (!irc_in_addr_valid(&i_addr(iauth).addr) && !ircd_aton(&i_addr(iauth).addr, i_host(iauth))) { @@ -472,6 +479,7 @@ static void iauth_reconnect(struct IAuth *iauth) sendto_opmask_butone(0, SNO_OLDSNO, "IAuth reconnect unable to initiate connection: %s", strerror(errno)); return; } + s_fd(&i_socket(iauth)) = fd; if (!socket_add(&i_socket(iauth), iauth_sock_callback, iauth, (result == IO_SUCCESS) ? SS_CONNECTED : SS_CONNECTING, SOCK_EVENT_READABLE | SOCK_EVENT_WRITABLE, fd)) { @@ -494,6 +502,10 @@ static void iauth_read(struct IAuth *iauth) length = 0; if (IO_FAILURE == os_recv_nonb(s_fd(&i_socket(iauth)), readbuf, sizeof(readbuf), &length)) return; + if (length == 0) { + iauth_reconnect(iauth); + return; + } i_recvB(iauth) += length; if (i_recvB(iauth) > 1023) { i_recvK(iauth) += i_recvB(iauth) >> 10; -- 2.20.1