diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-10 21:02:55 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-01-10 21:02:55 +0000 |
commit | ca61b7be5087dc21b32e2ad86c98e8fff9894157 (patch) | |
tree | 3f9920f2362b7dc7f15bdb407fa392c7ad08173d /usr.sbin/bgpd | |
parent | cfa2b96cf8fa327a58bdc95233bb5aff34456e57 (diff) |
we may only write after a POLLOUT, and then, we only may write once.
if we don't play by these rules the next write may block.
make us adhere.
ok claudio@
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r-- | usr.sbin/bgpd/buffer.c | 33 |
1 files changed, 8 insertions, 25 deletions
diff --git a/usr.sbin/bgpd/buffer.c b/usr.sbin/bgpd/buffer.c index a99967c1ca2..f7026dec044 100644 --- a/usr.sbin/bgpd/buffer.c +++ b/usr.sbin/bgpd/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.12 2004/01/06 03:43:50 henning Exp $ */ +/* $OpenBSD: buffer.c,v 1.13 2004/01/10 21:02:54 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -74,20 +74,6 @@ buf_reserve(struct buf *buf, ssize_t len) int buf_close(struct msgbuf *msgbuf, struct buf *buf) { - int n; - - /* first try to write out directly */ - if (msgbuf->queued == 0) { - if ((n = buf_write(msgbuf->sock, buf)) < 0) - return (n); - - if (n == 1) { /* all data written out */ - buf_free(buf); - return (0); - } - } - - /* we have to queue */ buf_enqueue(msgbuf, buf); return (1); } @@ -154,19 +140,16 @@ msgbuf_write(struct msgbuf *msgbuf) * we MUST return and NOT try to write out stuff from later buffers - * the socket might have become writeable again */ - struct buf *buf, *next; + struct buf *buf; int n; - for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL; buf = next) { - next = TAILQ_NEXT(buf, entries); - if ((n = buf_write(msgbuf->sock, buf)) < 0) - return (n); + buf = TAILQ_FIRST(&msgbuf->bufs); + if ((n = buf_write(msgbuf->sock, buf)) < 0) + return (n); + + if (n == 1) /* everything written out */ + buf_dequeue(msgbuf, buf); - if (n == 1) /* everything written out */ - buf_dequeue(msgbuf, buf); - else - return (0); - } return (0); } |