From ca61b7be5087dc21b32e2ad86c98e8fff9894157 Mon Sep 17 00:00:00 2001 From: Henning Brauer Date: Sat, 10 Jan 2004 21:02:55 +0000 Subject: 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@ --- usr.sbin/bgpd/buffer.c | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'usr.sbin/bgpd') 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 @@ -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); } -- cgit v1.2.3