+ else if (rc < 0) {
+ if (errno != EAGAIN) {
+ StopClientWatchers(IO, 1);
+ EV_syslog(LOG_DEBUG,
+ "EVENT: Socket Invalid! [%d] [%s] [%d]\n",
+ errno, strerror(errno), IO->SendBuf.fd);
+ StrBufPrintf(IO->ErrMsg,
+ "Socket Invalid! [%s]",
+ strerror(errno));
+ SetNextTimeout(IO, 0.0);
+ }
+ }
+ /* else : must write more. */
+}
+static void
+set_start_callback(struct ev_loop *loop, AsyncIO *IO, int revents)
+{
+ ev_timer_stop(event_base, &IO->conn_fail);
+ ev_timer_start(event_base, &IO->rw_timeout);
+
+ switch(IO->NextState) {
+ case eReadMore:
+ case eReadMessage:
+ case eReadFile:
+ StrBufAppendBufPlain(IO->ErrMsg, HKEY("[while waiting for greeting]"), 0);
+ ev_io_start(event_base, &IO->recv_event);
+ break;
+ case eSendReply:
+ case eSendMore:
+ case eReadPayload:
+ case eSendFile:
+ become_session(IO->CitContext);
+ IO_send_callback(loop, &IO->send_event, revents);
+ break;
+ case eDBQuery:
+ case eSendDNSQuery:
+ case eReadDNSReply:
+ case eConnect:
+ case eTerminateConnection:
+ case eAbort:
+ /// TODO: WHUT?
+ break;
+ }
+}
+
+static void
+IO_Timeout_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
+{
+ AsyncIO *IO = watcher->data;
+
+ IO->Now = ev_now(event_base);
+ ev_timer_stop (event_base, &IO->rw_timeout);
+ become_session(IO->CitContext);
+
+ if (IO->SendBuf.fd != 0)
+ {
+ ev_io_stop(event_base, &IO->send_event);
+ ev_io_stop(event_base, &IO->recv_event);
+ ev_timer_stop (event_base, &IO->rw_timeout);
+ close(IO->SendBuf.fd);
+ IO->SendBuf.fd = IO->RecvBuf.fd = 0;
+ }
+
+ assert(IO->Timeout);
+ switch (IO->Timeout(IO))
+ {
+ case eAbort:
+ ShutDownCLient(IO);
+ default:
+ break;
+ }
+}
+
+static void
+IO_connfail_callback(struct ev_loop *loop, ev_timer *watcher, int revents)
+{
+ AsyncIO *IO = watcher->data;
+
+ IO->Now = ev_now(event_base);
+ ev_timer_stop (event_base, &IO->conn_fail);
+
+ if (IO->SendBuf.fd != 0)
+ {
+ ev_io_stop(loop, &IO->conn_event);
+ ev_io_stop(event_base, &IO->send_event);
+ ev_io_stop(event_base, &IO->recv_event);
+ ev_timer_stop (event_base, &IO->rw_timeout);
+ 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_connfailimmediate_callback(struct ev_loop *loop,
+ ev_idle *watcher,
+ int revents)
+{
+ AsyncIO *IO = watcher->data;
+
+ IO->Now = ev_now(event_base);
+ 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: