summaryrefslogtreecommitdiff
path: root/usr.sbin/ldpd/buffer.c
diff options
context:
space:
mode:
authorJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-09-15 10:55:00 +0000
committerJacek Masiulaniec <jacekm@cvs.openbsd.org>2009-09-15 10:55:00 +0000
commit43985f9587646943ba4a959767965a408816239c (patch)
treeafb1260c2c2827d7a8f7391f3186c6f5941f0007 /usr.sbin/ldpd/buffer.c
parent3fc21b44e9512152a48c83f4a8f0da37a597ce65 (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/ldpd/buffer.c')
-rw-r--r--usr.sbin/ldpd/buffer.c48
1 files changed, 23 insertions, 25 deletions
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);
}