summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2016-11-20 08:43:37 +0000
committerEric Faurot <eric@cvs.openbsd.org>2016-11-20 08:43:37 +0000
commit42579984dfb52b4aa2ea48eb583af59dc13954ec (patch)
tree60e1628db013c647dd9499c44cb95b59f2e322ad
parentdb2ca73f0780fd3040a101e4d9585cbc52855188 (diff)
add dedicated functions to set fd and callback on a struct io.
simplify io_init() prototype. ok sunil@ gilles@
-rw-r--r--usr.sbin/smtpd/bounce.c6
-rw-r--r--usr.sbin/smtpd/filter.c8
-rw-r--r--usr.sbin/smtpd/ioev.c27
-rw-r--r--usr.sbin/smtpd/ioev.h7
-rw-r--r--usr.sbin/smtpd/mda.c7
-rw-r--r--usr.sbin/smtpd/mta_session.c7
-rw-r--r--usr.sbin/smtpd/smtp_session.c12
7 files changed, 47 insertions, 27 deletions
diff --git a/usr.sbin/smtpd/bounce.c b/usr.sbin/smtpd/bounce.c
index 505ae915ce4..05144e03b37 100644
--- a/usr.sbin/smtpd/bounce.c
+++ b/usr.sbin/smtpd/bounce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bounce.c,v 1.73 2016/11/16 21:30:37 eric Exp $ */
+/* $OpenBSD: bounce.c,v 1.74 2016/11/20 08:43:36 eric Exp $ */
/*
* Copyright (c) 2009 Gilles Chehade <gilles@poolp.org>
@@ -230,7 +230,9 @@ bounce_fd(int fd)
s->smtpname = xstrdup(msg->smtpname, "bounce_fd");
s->state = BOUNCE_EHLO;
iobuf_xinit(&s->iobuf, 0, 0, "bounce_run");
- io_init(&s->io, fd, s, bounce_io, &s->iobuf);
+ io_init(&s->io, &s->iobuf);
+ io_set_callback(&s->io, bounce_io, s);
+ io_set_fd(&s->io, fd);
io_set_timeout(&s->io, 30000);
io_set_read(&s->io);
s->boundary = generate_uid();
diff --git a/usr.sbin/smtpd/filter.c b/usr.sbin/smtpd/filter.c
index 456b522d954..516d378d8a6 100644
--- a/usr.sbin/smtpd/filter.c
+++ b/usr.sbin/smtpd/filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filter.c,v 1.20 2016/11/16 21:30:37 eric Exp $ */
+/* $OpenBSD: filter.c,v 1.21 2016/11/20 08:43:36 eric Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -315,7 +315,7 @@ filter_connect(uint64_t id, const struct sockaddr *local,
if (filter == NULL)
filter = "<no-filter>";
s->filters = dict_xget(&chains, filter);
- s->iev.sock = -1;
+ io_init(&s->iev, NULL);
tree_xset(&sessions, s->id, s);
filter_event(id, EVENT_CONNECT);
@@ -671,7 +671,9 @@ filter_tx(struct filter_session *s, int sink)
io_set_nonblocking(sp[1]);
iobuf_init(&s->ibuf, 0, 0);
- io_init(&s->iev, sp[0], s, filter_tx_io, &s->ibuf);
+ io_init(&s->iev, &s->ibuf);
+ io_set_callback(&s->iev, filter_tx_io, s);
+ io_set_fd(&s->iev, sp[0]);
io_set_read(&s->iev);
return (sp[1]);
diff --git a/usr.sbin/smtpd/ioev.c b/usr.sbin/smtpd/ioev.c
index 06bc35f2bf5..ab4aec07258 100644
--- a/usr.sbin/smtpd/ioev.c
+++ b/usr.sbin/smtpd/ioev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ioev.c,v 1.29 2016/11/17 17:34:55 eric Exp $ */
+/* $OpenBSD: ioev.c,v 1.30 2016/11/20 08:43:36 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -224,21 +224,15 @@ _io_init()
}
void
-io_init(struct io *io, int sock, void *arg,
- void(*cb)(struct io*, int, void *), struct iobuf *iobuf)
+io_init(struct io *io, struct iobuf *iobuf)
{
_io_init();
memset(io, 0, sizeof *io);
- io->sock = sock;
+ io->sock = -1;
io->timeout = -1;
- io->arg = arg;
io->iobuf = iobuf;
- io->cb = cb;
-
- if (sock != -1)
- io_reload(io);
}
void
@@ -289,6 +283,21 @@ io_release(struct io *io)
}
void
+io_set_fd(struct io *io, int fd)
+{
+ io->sock = fd;
+ if (fd != -1)
+ io_reload(io);
+}
+
+void
+io_set_callback(struct io *io, void(*cb)(struct io *, int, void *), void *arg)
+{
+ io->cb = cb;
+ io->arg = arg;
+}
+
+void
io_set_timeout(struct io *io, int msec)
{
io_debug("io_set_timeout(%p, %d)\n", io, msec);
diff --git a/usr.sbin/smtpd/ioev.h b/usr.sbin/smtpd/ioev.h
index dad320459a1..f57f885ad21 100644
--- a/usr.sbin/smtpd/ioev.h
+++ b/usr.sbin/smtpd/ioev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ioev.h,v 1.9 2016/11/17 17:34:55 eric Exp $ */
+/* $OpenBSD: ioev.h,v 1.10 2016/11/20 08:43:36 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -54,11 +54,12 @@ struct io {
void io_set_nonblocking(int);
void io_set_nolinger(int);
-void io_init(struct io*, int, void*, void(*)(struct io*, int, void *),
- struct iobuf*);
+void io_init(struct io*, struct iobuf*);
void io_clear(struct io*);
void io_set_read(struct io *);
void io_set_write(struct io *);
+void io_set_fd(struct io *, int);
+void io_set_callback(struct io *io, void(*)(struct io *, int, void *), void *);
void io_set_timeout(struct io *, int);
void io_set_lowat(struct io *, size_t);
void io_pause(struct io *, int);
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index 945a225bbbf..946d9752d66 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.121 2016/11/16 21:30:37 eric Exp $ */
+/* $OpenBSD: mda.c,v 1.122 2016/11/20 08:43:36 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -432,7 +432,7 @@ mda_imsg(struct mproc *p, struct imsg *imsg)
imsg->fd, s->id, s->evp->id);
io_set_nonblocking(imsg->fd);
- io_init(&s->io, imsg->fd, s, mda_io, &s->iobuf);
+ io_set_fd(&s->io, imsg->fd);
io_set_write(&s->io);
return;
@@ -955,9 +955,10 @@ mda_session(struct mda_user * u)
s = xcalloc(1, sizeof *s, "mda_session");
s->id = generate_uid();
s->user = u;
- s->io.sock = -1;
if (iobuf_init(&s->iobuf, 0, 0) == -1)
fatal("mda_session");
+ io_init(&s->io, &s->iobuf);
+ io_set_callback(&s->io, mda_io, s);
tree_xset(&sessions, s->id, s);
diff --git a/usr.sbin/smtpd/mta_session.c b/usr.sbin/smtpd/mta_session.c
index c782fd85a3a..98dbb47cfd0 100644
--- a/usr.sbin/smtpd/mta_session.c
+++ b/usr.sbin/smtpd/mta_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta_session.c,v 1.86 2016/11/18 09:35:27 eric Exp $ */
+/* $OpenBSD: mta_session.c,v 1.87 2016/11/20 08:43:36 eric Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -195,7 +195,7 @@ mta_session(struct mta_relay *relay, struct mta_route *route)
s->id = generate_uid();
s->relay = relay;
s->route = route;
- s->io.sock = -1;
+ io_init(&s->io, NULL);
if (relay->flags & RELAY_SSL && relay->flags & RELAY_AUTH)
s->flags |= MTA_USE_AUTH;
@@ -560,7 +560,8 @@ mta_connect(struct mta_session *s)
mta_enter_state(s, MTA_INIT);
iobuf_xinit(&s->iobuf, 0, 0, "mta_connect");
- io_init(&s->io, -1, s, mta_io, &s->iobuf);
+ io_init(&s->io, &s->iobuf);
+ io_set_callback(&s->io, mta_io, s);
io_set_timeout(&s->io, 300000);
if (io_connect(&s->io, sa, s->route->src->sa) == -1) {
/*
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index 29eca83b829..f1682c40742 100644
--- a/usr.sbin/smtpd/smtp_session.c
+++ b/usr.sbin/smtpd/smtp_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp_session.c,v 1.292 2016/11/18 09:35:27 eric Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.293 2016/11/20 08:43:36 eric Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -650,7 +650,9 @@ smtp_session(struct listener *listener, int sock,
s->id = generate_uid();
s->listener = listener;
memmove(&s->ss, ss, sizeof(*ss));
- io_init(&s->io, sock, s, smtp_io, &s->iobuf);
+ io_init(&s->io, &s->iobuf);
+ io_set_callback(&s->io, smtp_io, s);
+ io_set_fd(&s->io, sock);
io_set_timeout(&s->io, SMTPD_SESSION_TIMEOUT * 1000);
io_set_write(&s->io);
@@ -1202,7 +1204,9 @@ smtp_filter_fd(uint64_t id, int fd)
iobuf_init(&s->tx->obuf, 0, 0);
io_set_nonblocking(fd);
- io_init(&s->tx->oev, fd, s, smtp_data_io, &s->tx->obuf);
+ io_init(&s->tx->oev, &s->tx->obuf);
+ io_set_callback(&s->tx->oev, smtp_data_io, s);
+ io_set_fd(&s->tx->oev, fd);
iobuf_fqueue(&s->tx->obuf, "Received: ");
if (!(s->listener->flags & F_MASK_SOURCE)) {
@@ -1421,7 +1425,7 @@ smtp_tx(struct smtp_session *s)
return 0;
TAILQ_INIT(&tx->rcpts);
- io_init(&tx->oev, -1, s, NULL, NULL); /* initialise 'sock', but not to 0 */
+ io_init(&tx->oev, NULL);
s->tx = tx;
tx->session = s;