diff options
author | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-09-15 10:55:00 +0000 |
---|---|---|
committer | Jacek Masiulaniec <jacekm@cvs.openbsd.org> | 2009-09-15 10:55:00 +0000 |
commit | 43985f9587646943ba4a959767965a408816239c (patch) | |
tree | afb1260c2c2827d7a8f7391f3186c6f5941f0007 /usr.sbin | |
parent | 3fc21b44e9512152a48c83f4a8f0da37a597ce65 (diff) |
Enclose repeated buffer draining code in a new msgbuf_drain()
function, which is additionally exported for use by others.
It will be needed by smtpd's SSL module when the SMTP client code
is changed to replace libevent's evbuffers with our msgbuf_* API.
ok gilles@ henning@ guenther@ eric@
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/bgpd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/dvmrpd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/ldpd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/ldpd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/ntpd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/ntpd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/ospf6d/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/ospf6d/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/ospfd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/ospfd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/relayd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/relayd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/ripd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/ripd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/smtpd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/snmpd/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/snmpd/imsg.h | 3 | ||||
-rw-r--r-- | usr.sbin/ypldap/buffer.c | 48 | ||||
-rw-r--r-- | usr.sbin/ypldap/imsg.h | 3 |
22 files changed, 275 insertions, 286 deletions
diff --git a/usr.sbin/bgpd/buffer.c b/usr.sbin/bgpd/buffer.c index 70c793bd4b3..0d8a465b8f9 100644 --- a/usr.sbin/bgpd/buffer.c +++ b/usr.sbin/bgpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.44 2009/07/23 18:58:42 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.45 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/bgpd/imsg.h b/usr.sbin/bgpd/imsg.h index 8fa2e4f2da0..bd2bada5a3b 100644 --- a/usr.sbin/bgpd/imsg.h +++ b/usr.sbin/bgpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:24 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/dvmrpd/buffer.c b/usr.sbin/dvmrpd/buffer.c index 6717ea3da47..adba24d73d2 100644 --- a/usr.sbin/dvmrpd/buffer.c +++ b/usr.sbin/dvmrpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.4 2009/07/23 18:58:42 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.5 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/dvmrpd/imsg.h b/usr.sbin/dvmrpd/imsg.h index 427e3e1468c..bd2bada5a3b 100644 --- a/usr.sbin/dvmrpd/imsg.h +++ b/usr.sbin/dvmrpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/ldpd/buffer.c b/usr.sbin/ldpd/buffer.c index f9917ee461d..603a53d60ff 100644 --- a/usr.sbin/ldpd/buffer.c +++ b/usr.sbin/ldpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.3 2009/07/23 18:58:42 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/ldpd/imsg.h b/usr.sbin/ldpd/imsg.h index 427e3e1468c..bd2bada5a3b 100644 --- a/usr.sbin/ldpd/imsg.h +++ b/usr.sbin/ldpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/ntpd/buffer.c b/usr.sbin/ntpd/buffer.c index b7693cde559..c8a11378143 100644 --- a/usr.sbin/ntpd/buffer.c +++ b/usr.sbin/ntpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.11 2009/07/23 18:58:42 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.12 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/ntpd/imsg.h b/usr.sbin/ntpd/imsg.h index 427e3e1468c..bd2bada5a3b 100644 --- a/usr.sbin/ntpd/imsg.h +++ b/usr.sbin/ntpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/ospf6d/buffer.c b/usr.sbin/ospf6d/buffer.c index 6717ea3da47..adba24d73d2 100644 --- a/usr.sbin/ospf6d/buffer.c +++ b/usr.sbin/ospf6d/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.4 2009/07/23 18:58:42 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.5 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/ospf6d/imsg.h b/usr.sbin/ospf6d/imsg.h index 427e3e1468c..bd2bada5a3b 100644 --- a/usr.sbin/ospf6d/imsg.h +++ b/usr.sbin/ospf6d/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/ospfd/buffer.c b/usr.sbin/ospfd/buffer.c index c5fddc10e95..68789a16dbf 100644 --- a/usr.sbin/ospfd/buffer.c +++ b/usr.sbin/ospfd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.16 2009/07/23 18:58:42 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.17 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/ospfd/imsg.h b/usr.sbin/ospfd/imsg.h index 8a93607cac8..c4e7247c7c6 100644 --- a/usr.sbin/ospfd/imsg.h +++ b/usr.sbin/ospfd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.7 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.8 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/relayd/buffer.c b/usr.sbin/relayd/buffer.c index a1d86146e92..512afa59022 100644 --- a/usr.sbin/relayd/buffer.c +++ b/usr.sbin/relayd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.21 2009/07/23 18:58:42 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.22 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/relayd/imsg.h b/usr.sbin/relayd/imsg.h index c1bf0075908..42394bdda5d 100644 --- a/usr.sbin/relayd/imsg.h +++ b/usr.sbin/relayd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.12 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.13 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/ripd/buffer.c b/usr.sbin/ripd/buffer.c index 03a7fe8798a..adba24d73d2 100644 --- a/usr.sbin/ripd/buffer.c +++ b/usr.sbin/ripd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.4 2009/07/23 18:58:43 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.5 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/ripd/imsg.h b/usr.sbin/ripd/imsg.h index 427e3e1468c..bd2bada5a3b 100644 --- a/usr.sbin/ripd/imsg.h +++ b/usr.sbin/ripd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/smtpd/buffer.c b/usr.sbin/smtpd/buffer.c index ae5870d92a9..96661c33723 100644 --- a/usr.sbin/smtpd/buffer.c +++ b/usr.sbin/smtpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.5 2009/07/23 18:58:43 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.6 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/smtpd/imsg.h b/usr.sbin/smtpd/imsg.h index 2b56432d527..6facd687c81 100644 --- a/usr.sbin/smtpd/imsg.h +++ b/usr.sbin/smtpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.5 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.6 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/snmpd/buffer.c b/usr.sbin/snmpd/buffer.c index 82e4deb0ebc..214cc25109d 100644 --- a/usr.sbin/snmpd/buffer.c +++ b/usr.sbin/snmpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.8 2009/07/23 18:58:43 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.9 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/snmpd/imsg.h b/usr.sbin/snmpd/imsg.h index 427e3e1468c..bd2bada5a3b 100644 --- a/usr.sbin/snmpd/imsg.h +++ b/usr.sbin/snmpd/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); diff --git a/usr.sbin/ypldap/buffer.c b/usr.sbin/ypldap/buffer.c index 243255c28b1..603a53d60ff 100644 --- a/usr.sbin/ypldap/buffer.c +++ b/usr.sbin/ypldap/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.3 2009/07/23 18:58:43 eric Exp $ */ +/* $OpenBSD: buffer.c,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -144,7 +144,7 @@ int buf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; @@ -170,17 +170,7 @@ buf_write(struct msgbuf *msgbuf) return (-2); } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } @@ -201,6 +191,24 @@ msgbuf_init(struct msgbuf *msgbuf) } void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) +{ + struct buf *buf, *next; + + for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; + buf = next) { + next = TAILQ_NEXT(buf, entry); + if (buf->rpos + n >= buf->wpos) { + n -= buf->wpos - buf->rpos; + buf_dequeue(msgbuf, buf); + } else { + buf->rpos += n; + n = 0; + } + } +} + +void msgbuf_clear(struct msgbuf *msgbuf) { struct buf *buf; @@ -213,7 +221,7 @@ int msgbuf_write(struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; - struct buf *buf, *next; + struct buf *buf; unsigned int i = 0; ssize_t n; struct msghdr msg; @@ -270,17 +278,7 @@ msgbuf_write(struct msgbuf *msgbuf) buf->fd = -1; } - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { - next = TAILQ_NEXT(buf, entry); - if (buf->rpos + n >= buf->wpos) { - n -= buf->wpos - buf->rpos; - buf_dequeue(msgbuf, buf); - } else { - buf->rpos += n; - n = 0; - } - } + msgbuf_drain(msgbuf, n); return (0); } diff --git a/usr.sbin/ypldap/imsg.h b/usr.sbin/ypldap/imsg.h index 427e3e1468c..bd2bada5a3b 100644 --- a/usr.sbin/ypldap/imsg.h +++ b/usr.sbin/ypldap/imsg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg.h,v 1.3 2009/06/07 05:56:25 eric Exp $ */ +/* $OpenBSD: imsg.h,v 1.4 2009/09/15 10:54:59 jacekm Exp $ */ /* * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -90,6 +90,7 @@ void buf_free(struct buf *); void msgbuf_init(struct msgbuf *); void msgbuf_clear(struct msgbuf *); int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ void imsg_init(struct imsgbuf *, int); |