summaryrefslogtreecommitdiffstats
path: root/compat/imsg-buffer.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2009-09-15 23:59:40 +0000
committerTiago Cunha <tcunha@gmx.com>2009-09-15 23:59:40 +0000
commit150fba5ecdb3fedd8aed71ee65fb8cc6b0354070 (patch)
tree6add6c56f5524aed360ecd33050ebcf427a34bfa /compat/imsg-buffer.c
parentc507bf25decf7366ea31e1af16ade117a8d2398a (diff)
Sync OpenBSD patchset 329:
Enclose repeated buffer draining code in a new msgbuf_drain() function, which is additionally exported for use by others. From nicm@, who reminded me that tmux is now using buffer.c, too.
Diffstat (limited to 'compat/imsg-buffer.c')
-rw-r--r--compat/imsg-buffer.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/compat/imsg-buffer.c b/compat/imsg-buffer.c
index 41cf0346..ebfd3ab7 100644
--- a/compat/imsg-buffer.c
+++ b/compat/imsg-buffer.c
@@ -1,5 +1,5 @@
-/* $Id: imsg-buffer.c,v 1.3 2009-08-20 12:54:08 nicm Exp $ */
-/* $OpenBSD: imsg-buffer.c,v 1.1 2009/08/11 17:18:35 nicm Exp $ */
+/* $Id: imsg-buffer.c,v 1.4 2009-09-15 23:59:40 tcunha Exp $ */
+/* $OpenBSD: imsg-buffer.c,v 1.2 2009/09/15 18:12:51 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);
}