Fix several bugs in iauth code.
authorMichael Poole <mdpoole@troilus.org>
Sun, 1 May 2005 01:48:12 +0000 (01:48 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sun, 1 May 2005 01:48:12 +0000 (01:48 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1391 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/ircd_auth.c

index 94cbea43b248e512adcbb501bb3ec24a39751e3c..de627dcb5f19816d3efc284ab12e024ff9715e12 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-04-30  Michael Poole <mdpoole@troilus.org>
+
+       * 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 <mdpoole@troilus.org>
 
        * ircd/ircd_parser.y: Report non-existent class names as errors
index 7487fd5156cc7e91205df637c373f1f7c3178cd5..e9441625bb297e7ad93235eb27b747829d0e89ac 100644 (file)
@@ -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;