diff options
author | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-12-23 17:16:04 +0000 |
---|---|---|
committer | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-12-23 17:16:04 +0000 |
commit | 4fd4f966eabc8c57cefe1362f25724002f0e535e (patch) | |
tree | 481f83ea213e20afb6ea3e090ca1f96c0b9342f1 /usr.sbin/smtpd/bounce.c | |
parent | 22f4b7bfb9c9331c9bbccb00a1f046568d0a205c (diff) |
Implementation of RFC 2920 PIPELINING extension, client side only for now.
This restructures the client_* API internals significantly. The code becomes
pipelining in nature. All SMTP commands are put on the output queue and
dequeued as quickly as possible. Once dequeued, they're moved to the receive
queue so that replies can be matched with previous commands.
Dequeuing commands from the output queue halts when the count of commands
currently in-pipeline (``cmdi'') is equal to the command send window (``cmdw'').
There are three cmdw values useful in practice:
0 clear pipeline, ie. inhibit all future sends
1 disable pipelining, ie. use old ``one-request-one-reply`` mode
SIZE_T_MAX enable pipelining, ie. dequeue as many commands as possible
At the beginning of session cmdw is 1. When it is found that peer supports
PIPELINING, it grows to SIZE_T_MAX. After dequeing DATA it is again 1. After
sending QUIT it is 0.
Each command dequeued from the output queue becomes a buf in a msgbuf. The act
of combining multiple commands into a single send operation did not need to be
implemented: buf_write() already combines bufs using iovec and sends them at
once using sendmsg(2).
Tested by todd@ and oga@
"looks good" to gilles@
Diffstat (limited to 'usr.sbin/smtpd/bounce.c')
-rw-r--r-- | usr.sbin/smtpd/bounce.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/usr.sbin/smtpd/bounce.c b/usr.sbin/smtpd/bounce.c index e473103270a..7974c661282 100644 --- a/usr.sbin/smtpd/bounce.c +++ b/usr.sbin/smtpd/bounce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bounce.c,v 1.16 2009/12/14 23:17:04 jacekm Exp $ */ +/* $OpenBSD: bounce.c,v 1.17 2009/12/23 17:16:03 jacekm Exp $ */ /* * Copyright (c) 2009 Gilles Chehade <gilles@openbsd.org> @@ -71,8 +71,7 @@ bounce_session(struct smtpd *env, int fd, struct message *messagep) cc->m = *messagep; client_ssl_optional(cc->pcb); - - /* assign recipient */ + client_sender(cc->pcb, ""); client_rcpt(cc->pcb, NULL, "%s@%s", messagep->sender.user, messagep->sender.domain); @@ -108,7 +107,7 @@ bounce_session(struct smtpd *env, int fd, struct message *messagep) /* setup event */ session_socket_blockmode(fd, BM_NONBLOCK); - event_set(&cc->ev, fd, EV_WRITE, bounce_event, cc); + event_set(&cc->ev, fd, EV_READ|EV_WRITE, bounce_event, cc); event_add(&cc->ev, &cc->pcb->timeout); return 1; @@ -131,11 +130,11 @@ bounce_event(int fd, short event, void *p) goto out; } - switch (client_talk(cc->pcb)) { - case CLIENT_WANT_READ: - goto read; + switch (client_talk(cc->pcb, event & EV_WRITE)) { + case CLIENT_STOP_WRITE: + goto ro; case CLIENT_WANT_WRITE: - goto write; + goto rw; case CLIENT_RCPT_FAIL: ep = cc->pcb->reply; break; @@ -164,12 +163,12 @@ out: free(cc); return; -read: +ro: event_set(&cc->ev, fd, EV_READ, bounce_event, cc); event_add(&cc->ev, &cc->pcb->timeout); return; -write: - event_set(&cc->ev, fd, EV_WRITE, bounce_event, cc); +rw: + event_set(&cc->ev, fd, EV_READ|EV_WRITE, bounce_event, cc); event_add(&cc->ev, &cc->pcb->timeout); } |