=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/Attic/imsg-buffer.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- src/usr.bin/tmux/Attic/imsg-buffer.c 2009/08/11 17:18:35 1.1 +++ src/usr.bin/tmux/Attic/imsg-buffer.c 2009/09/15 18:12:51 1.2 @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg-buffer.c,v 1.1 2009/08/11 17:18:35 nicm Exp $ */ +/* $OpenBSD: imsg-buffer.c,v 1.2 2009/09/15 18:12:51 jacekm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -144,7 +144,7 @@ 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 @@ 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 @@ } 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 @@ 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 @@ 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); }