(reads *should* not block, since they only occur when the
I/O thread gets a readability event).
#include <stdlib.h>
#include <unistd.h>
+#include <fcntl.h>
#include <assert.h>
#include <string.h>
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);
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
+#include <sys/errno.h>
#include <assert.h>
#include <ctype.h>
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))) {