fix loop / handling error when connecting fails immediately
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 6 Jun 2011 19:33:58 +0000 (19:33 +0000)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 6 Jun 2011 19:33:58 +0000 (19:33 +0000)
  - add new ev_idle to unwind the stack on connecting
  - add a new handler that processes the disconnect

citadel/event_client.c
citadel/event_client.h

index 3791e6d2db7a1b45a0153f88d7a0064f6f53a583..37a943a45e90cd909b40e5099291c7ac1770a3a2 100644 (file)
@@ -337,6 +337,7 @@ IO_Timeout_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
                break;
        }
 }
+
 static void
 IO_connfail_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
 {
@@ -365,6 +366,32 @@ IO_connfail_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
 
        }
 }
+
+static void
+IO_connfailimmediate_callback(struct ev_loop *loop, ev_idle *watcher, int revents)
+{
+       AsyncIO *IO = watcher->data;
+
+       ev_idle_stop (event_base, &IO->conn_fail_immediate);
+
+       if (IO->SendBuf.fd != 0)
+       {
+               close(IO->SendBuf.fd);
+               IO->SendBuf.fd = IO->RecvBuf.fd = 0;
+       }
+       become_session(IO->CitContext);
+
+       assert(IO->ConnFail);
+        switch (IO->ConnFail(IO))
+       {
+       case eAbort:
+               ShutDownCLient(IO);
+       default:
+               break;
+
+       }
+}
+
 static void
 IO_connestd_callback(struct ev_loop *loop, ev_io *watcher, int revents)
 {
@@ -487,11 +514,14 @@ eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_r
                return IO->NextState;
        }
        else {
+               ev_idle_init(&IO->conn_fail_immediate,
+                            IO_connfailimmediate_callback);
+               IO->conn_fail_immediate.data = IO;
+               ev_idle_start(event_base, &IO->conn_fail_immediate);
+               
                CtdlLogPrintf(CTDL_ERR, "connect() failed: %s\n", strerror(errno));
                StrBufPrintf(IO->ErrMsg, "Failed to connect: %s", strerror(errno));
-               assert(IO->ConnFail);
-               IO->ConnFail(IO);
-               return eAbort;
+               return IO->NextState;
        }
        return IO->NextState;
 }
index 49d1159783ba1a50380e9485a932d27adb012dea..a3d467db072ca2b3aff780ba54e48c81b40633e8 100644 (file)
@@ -65,7 +65,8 @@ struct AsyncIO {
        ev_cleanup abort_by_shutdown; /* server wants to go down... */
        ev_timer conn_fail,           /* connection establishing timed out */
                rw_timeout;           /* timeout while sending data */
-       ev_idle unwind_stack;         /* get c-ares out of the stack */
+       ev_idle unwind_stack,         /* get c-ares out of the stack */
+               conn_fail_immediate;  /* unwind stack, but fail immediately. */
        ev_io recv_event,             /* receive data from the client */
                send_event,           /* send more data to the client */
                conn_event;           /* Connection successfully established */