void ShutDownCLient(AsyncIO *IO)
{
- CtdlLogPrintf(CTDL_DEBUG, "EVENT x %d\n", IO->sock);
+ CtdlLogPrintf(CTDL_DEBUG, "EVENT x %d\n", IO->SendBuf.fd);
ev_cleanup_stop(event_base, &IO->abort_by_shutdown);
- if (IO->sock != 0)
+ 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->sock);
- IO->sock = 0;
+ close(IO->SendBuf.fd);
IO->SendBuf.fd = 0;
IO->RecvBuf.fd = 0;
}
pchh = pch;
nbytes = StrLength(IO->SendBuf.Buf) - (pchh - pch);
- snprintf(fn, SIZ, "/tmp/foolog_ev_%s.%d", "smtpev", IO->sock);
+ snprintf(fn, SIZ, "/tmp/foolog_ev_%s.%d", "smtpev", IO->SendBuf.fd);
fd = fopen(fn, "a+");
fprintf(fd, "Read: BufSize: %ld BufContent: [",
int rc = -1;
IO->SendBuf.fd = IO->RecvBuf.fd =
- IO->sock = socket(
+ socket(
(IO->ConnectMe->IPv6)?PF_INET6:PF_INET,
SOCK_STREAM,
IPPROTO_TCP);
- if (IO->sock < 0) {
+ if (IO->SendBuf.fd < 0) {
CtdlLogPrintf(CTDL_ERR, "EVENT: socket() failed: %s\n", strerror(errno));
StrBufPrintf(IO->ErrMsg, "Failed to create socket: %s", strerror(errno));
// freeaddrinfo(res);
return eAbort;
}
- fdflags = fcntl(IO->sock, F_GETFL);
+ fdflags = fcntl(IO->SendBuf.fd, F_GETFL);
if (fdflags < 0) {
CtdlLogPrintf(CTDL_DEBUG,
"EVENT: unable to get socket flags! %s \n",
return eAbort;
}
fdflags = fdflags | O_NONBLOCK;
- if (fcntl(IO->sock, F_SETFL, fdflags) < 0) {
+ if (fcntl(IO->SendBuf.fd, F_SETFL, fdflags) < 0) {
CtdlLogPrintf(CTDL_DEBUG,
"EVENT: unable to set socket nonblocking flags! %s \n",
strerror(errno));
StrBufPrintf(IO->ErrMsg, "Failed to set socket flags: %s", strerror(errno));
- close(IO->sock);
+ close(IO->SendBuf.fd);
+ IO->SendBuf.fd = IO->RecvBuf.fd = -1;
return eAbort;
}
/* TODO: maye we could use offsetof() to calc the position of data...
* http://doc.dvgu.ru/devel/ev.html#associating_custom_data_with_a_watcher
*/
- ev_io_init(&IO->recv_event, IO_recv_callback, IO->sock, EV_READ);
+ ev_io_init(&IO->recv_event, IO_recv_callback, IO->RecvBuf.fd, EV_READ);
IO->recv_event.data = IO;
- ev_io_init(&IO->send_event, IO_send_callback, IO->sock, EV_WRITE);
+ ev_io_init(&IO->send_event, IO_send_callback, IO->SendBuf.fd, EV_WRITE);
IO->send_event.data = IO;
ev_timer_init(&IO->conn_fail, IO_connfail_callback, conn_timeout, 0);
IO->rw_timeout.data = IO;
if (IO->ConnectMe->IPv6)
- rc = connect(IO->sock, &IO->ConnectMe->Addr, sizeof(struct sockaddr_in6));
+ rc = connect(IO->SendBuf.fd, &IO->ConnectMe->Addr, sizeof(struct sockaddr_in6));
else
- rc = connect(IO->sock, (struct sockaddr_in *)&IO->ConnectMe->Addr, sizeof(struct sockaddr_in));
+ rc = connect(IO->SendBuf.fd, (struct sockaddr_in *)&IO->ConnectMe->Addr, sizeof(struct sockaddr_in));
if (rc >= 0){
//// freeaddrinfo(res);
}
else if (errno == EINPROGRESS) {
- ev_io_init(&IO->conn_event, IO_connestd_callback, IO->sock, EV_READ|EV_WRITE);
+ ev_io_init(&IO->conn_event, IO_connestd_callback, IO->SendBuf.fd, EV_READ|EV_WRITE);
IO->conn_event.data = IO;
ev_io_start(event_base, &IO->conn_event);
struct AsyncIO {
+ eNextState NextState;
/* connection related */
ParsedURL *ConnectMe;
-/*
- int IP6;
- struct sockaddr_in6 *Addr;
- unsigned short dport;
-
-*/
- int sock;
- eNextState NextState;
- ev_cleanup abort_by_shutdown;
-
- ev_timer conn_fail,
- rw_timeout;
- ev_idle unwind_stack;
- ev_io recv_event,
- send_event,
- conn_event;
- StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
-
/* read/send related... */
StrBuf *IOBuf;
IOBuffer SendBuf,
RecvBuf;
+ /* our events... */
+ 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_io recv_event, /* receive data from the client */
+ send_event, /* send more data to the client */
+ conn_event; /* Connection successfully established */
+
+ StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
+
/* Citadel application callbacks... */
IO_CallBack ReadDone, /* Theres new data to read... */
SendDone, /* we may send more data */
IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
+ /* DNS Related */
ev_io dns_recv_event,
dns_send_event;
struct ares_options DNSOptions;
DNSQueryParts *DNSQuery;
/* Custom data; its expected to contain AsyncIO so we can save malloc()s... */
- DeleteHashDataFunc DeleteData; /* so if we have to destroy you, what to do... */
- void *Data; /* application specific data */
+ void *Data; /* application specific data */
+ void *CitContext; /* Citadel Session context... */
};
typedef struct _IOAddHandler {