#define SEND_EVENT 1
#define RECV_EVENT 2
-#define CONN_EVENT 3
int QueueEventContext(void *Ctx, AsyncIO *IO, EventContextAttach CB)
{
case RECV_EVENT:
ev_io_stop(event_base, &IO->recv_event);
break;
- case CONN_EVENT:
- ev_io_stop(event_base, &IO->conn_event);
- break;
case 0:
// no event active here; just bail out.
break;
static void
-set_start_callback(struct ev_loop *loop, ev_io *watcher, int revents)
+set_start_callback(struct ev_loop *loop, AsyncIO *IO, int revents)
{
- AsyncIO *IO = watcher->data;
-
switch(IO->NextState) {
case eReadMessage:
ev_io_start(event_base, &IO->recv_event);
break;
case eSendReply:
case eSendMore:
- IO_send_callback(loop, watcher, revents);
+ IO_send_callback(loop, &IO->send_event, revents);
break;
case eTerminateConnection:
case eAbort:
}
}
-static void
-IO_connect_callback(struct ev_loop *loop, ev_io *watcher, int revents)
-{
- AsyncIO *IO = watcher->data;
-
- ev_io_stop(event_base, &IO->conn_event);
- IO->active_event = 0;
- set_start_callback(loop, watcher, revents);
-}
-
int event_connect_socket(AsyncIO *IO)
{
int fdflags;
/// TODO: ipv6?? (IO->HEnt->h_addrtype == AF_INET6)?
/* sizeof(in6_addr):*/
sizeof(struct sockaddr_in));
- if (rc >= 0) {
+ if ((rc >= 0) || (errno == EINPROGRESS)){
//// freeaddrinfo(res);
- ev_io_init(&IO->conn_event, IO_send_callback, IO->sock, EV_WRITE);
- IO->conn_event.data = IO;
- set_start_callback(event_base, &IO->conn_event, 0);
+ set_start_callback(event_base, IO, 0);
return 0;
}
- else if (errno == EINPROGRESS) {
- ev_io_init(&IO->conn_event, IO_connect_callback, IO->sock, EV_WRITE);
- IO->conn_event.data = IO;
-/* TODO
-
- event_set(&IO->conn_event,
- IO->sock,
- EV_READ|EV_WRITE|EV_PERSIST,
- IO_connect_callback,
- IO);
-*/
- ev_io_start(event_base, &IO->conn_event);
-
- IO->active_event = CONN_EVENT;
- return 1;
- }
else {
CtdlLogPrintf(CTDL_ERR, "connect() failed: %s\n", strerror(errno));
StrBufPrintf(IO->ErrMsg, "Failed to connect: %s", strerror(errno));
IO->ReadDone = ReadDone;
IO->Terminate = Terminate;
IO->LineReader = LineReader;
-
+
if (ReadFirst) {
IO->NextState = eReadMessage;
}
int active_event;
eNextState NextState;
ev_io recv_event,
- send_event,
- conn_event;
+ send_event;
StrBuf *ErrMsg; /* if we fail to connect, or lookup, error goes here. */
/* read/send related... */
SendDone, /* we may send more data */
Terminate, /* shutting down... */
Timeout, /* Timeout handler; may also be connection timeout */
- ConnFail, /* What to do when one connection failed? */
- CustomDNS; /* If the application wants to do custom dns functionality like cycle through different MX-Records */
+ ConnFail; /* What to do when one connection failed? */
IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
SendMsg->mx_port = DefaultMXPort;
+ SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
+ SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
+ SendMsg->IO.IOBuf = NewStrBuf();
+ SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
+
/* TODO: Relay!
*SendMsg->mx_user = '\0';
*SendMsg->mx_pass = '\0';
int resolve_mx_records(void *Ctx)
{
SmtpOutMsg * SendMsg = Ctx;
+///TMP
+ SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
+ SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
+ SendMsg->IO.IOBuf = NewStrBuf();
+ SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
InitEventIO(&SendMsg->IO, SendMsg,
SMTP_C_DispatchReadDone,
SMTP_C_ReadServerStatus,
1);
return 0;
+/// END TMP */
if (!QueueQuery(ns_t_mx,
SendMsg->node,
&SendMsg->IO,