--- /dev/null
- c->state = SMTP_CLOSED;
- return 0;
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dlfcn.h>
+#include <unistd.h>
++#include <sys/errno.h>
+#include <assert.h>
+#include <err.h>
+
+#include <sys/queue.h>
+#include <netinet/in.h>
+#include <event.h>
+#include "smtpsink.h"
+
+int
+respond(struct conn *c, const char *fmt, ...)
+{
+ va_list ap;
+ char buf[2048];
+ int ret, nw;
+
+ va_start(ap, fmt);
+ ret = vsnprintf(buf, sizeof(buf), fmt, ap);
+ if (ret < 0) assert(0);
+ nw = write(c->fd, buf, ret);
+ if (nw < 0) {
++ if (errno != EAGAIN) {
++ c->state = SMTP_CLOSED;
++ return 0;
++ }
++ nw = 0;
+ }
+ if (nw < ret) {
+ if (!(c->wdata.s = malloc(ret - nw))) {
+ c->state = SMTP_CLOSED;
+ return 0;
+ }
+ memcpy(c->wdata.s, buf + nw, ret - nw);
+ c->wdata.off = 0;
+ c->wdata.len = ret - nw;
+ return 0;
+ }
+ return 1;
+}
+
+void *
+ssm_getpriv(struct smtpsink_module *m, struct conn *c)
+{
+ assert(c->priv_data);
+ return c->priv_data[m->ssm_module_index];
+}
+
+void
+ssm_setpriv(struct smtpsink_module *m, struct conn *c, void *data)
+{
+ assert(c->priv_data);
+ c->priv_data[m->ssm_module_index] = data;
+}