From 6811223ddffb40fad91977f18ef120628080bc0b Mon Sep 17 00:00:00 2001 From: chris mikkelson Date: Wed, 1 Apr 2009 23:47:31 -0500 Subject: [PATCH] Set connection fds to nonblocking, detect blocked writes (reads *should* not block, since they only occur when the I/O thread gets a readability event). --- io.c | 4 ++++ smtp.c | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/io.c b/io.c index 2d56936..537a14b 100644 --- a/io.c +++ b/io.c @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -96,6 +97,9 @@ write_cb(int fd, short event, void *data) void io_initconn(struct conn *c) { + int flags = fcntl(c->fd, F_GETFL); + flags |= O_NONBLOCK; + fcntl(c->fd, F_SETFL, flags); event_set(&c->re, c->fd, EV_READ, read_cb, (void *)c); event_base_set(io_base, &c->re); event_set(&c->we, c->fd, EV_WRITE, write_cb, (void *)c); diff --git a/smtp.c b/smtp.c index 7b16300..187f728 100644 --- a/smtp.c +++ b/smtp.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -39,8 +40,11 @@ respond(struct conn *c, const char *fmt, ...) if (ret < 0) assert(0); nw = write(c->fd, buf, ret); if (nw < 0) { - c->state = SMTP_CLOSED; - return 0; + if (errno != EAGAIN) { + c->state = SMTP_CLOSED; + return 0; + } + nw = 0; } if (nw < ret) { if (!(c->wdata.s = malloc(ret - nw))) { -- 2.50.1