summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-05 01:19:10 +0000
committerPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-05 01:19:10 +0000
commit41d607b5268ed1274426b6506ef9e48729d011df (patch)
tree40422c8104a4dd3ea542017700573d056614fef3
parentf7864e423d02d1409e5dfc70f4afb0e2a05a946b (diff)
treat buf->wpos as the size to send out on the wire, not buf->size,
this plays better with dynamic buffers which are now the norm. ok by a slightly annoyed claudio@, ok eric@
-rw-r--r--usr.sbin/ospfd/buffer.c13
-rw-r--r--usr.sbin/ospfd/imsg.c15
-rw-r--r--usr.sbin/ospfd/ospfd.h4
3 files changed, 10 insertions, 22 deletions
diff --git a/usr.sbin/ospfd/buffer.c b/usr.sbin/ospfd/buffer.c
index c6e6aff7459..ab6bad9169a 100644
--- a/usr.sbin/ospfd/buffer.c
+++ b/usr.sbin/ospfd/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.11 2009/03/04 12:51:01 claudio Exp $ */
+/* $OpenBSD: buffer.c,v 1.12 2009/06/05 01:19:09 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -133,13 +133,10 @@ buf_left(struct buf *buf)
return (buf->max - buf->wpos);
}
-int
+void
buf_close(struct msgbuf *msgbuf, struct buf *buf)
{
- /* truncate buffer to the correct length before queuing */
- buf->size = buf->wpos;
buf_enqueue(msgbuf, buf);
- return (1);
}
void
@@ -181,7 +178,7 @@ msgbuf_write(struct msgbuf *msgbuf)
if (i >= IOV_MAX)
break;
iov[i].iov_base = buf->buf + buf->rpos;
- iov[i].iov_len = buf->size - buf->rpos;
+ iov[i].iov_len = buf->wpos - buf->rpos;
i++;
}
@@ -204,8 +201,8 @@ msgbuf_write(struct msgbuf *msgbuf)
for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
buf = next) {
next = TAILQ_NEXT(buf, entry);
- if (buf->rpos + n >= buf->size) {
- n -= buf->size - buf->rpos;
+ if (buf->rpos + n >= buf->wpos) {
+ n -= buf->wpos - buf->rpos;
buf_dequeue(msgbuf, buf);
} else {
buf->rpos += n;
diff --git a/usr.sbin/ospfd/imsg.c b/usr.sbin/ospfd/imsg.c
index ef14fb8d088..e3baac0c432 100644
--- a/usr.sbin/ospfd/imsg.c
+++ b/usr.sbin/ospfd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.10 2009/03/04 12:51:01 claudio Exp $ */
+/* $OpenBSD: imsg.c,v 1.11 2009/06/05 01:19:09 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -162,17 +162,8 @@ imsg_close(struct imsgbuf *ibuf, struct buf *msg)
struct imsg_hdr *hdr;
hdr = (struct imsg_hdr *)msg->buf;
- if (msg->size != msg->wpos) {
- log_warnx("imsg_close: buffer is not correctly filled");
- buf_free(msg);
- return (-1);
- }
- hdr->len = (u_int16_t)msg->size;
- if (buf_close(&ibuf->w, msg) < 0) {
- log_warnx("imsg_close: buf_close error");
- buf_free(msg);
- return (-1);
- }
+ hdr->len = (u_int16_t)msg->wpos;
+ buf_close(&ibuf->w, msg);
imsg_event_add(ibuf);
return (0);
diff --git a/usr.sbin/ospfd/ospfd.h b/usr.sbin/ospfd/ospfd.h
index 0e1d6c805db..5e12dc38e78 100644
--- a/usr.sbin/ospfd/ospfd.h
+++ b/usr.sbin/ospfd/ospfd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfd.h,v 1.78 2009/06/02 20:16:59 claudio Exp $ */
+/* $OpenBSD: ospfd.h,v 1.79 2009/06/05 01:19:09 pyr Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -566,7 +566,7 @@ void *buf_reserve(struct buf *, size_t);
void *buf_seek(struct buf *, size_t, size_t);
size_t buf_size(struct buf *);
size_t buf_left(struct buf *);
-int buf_close(struct msgbuf *, struct buf *);
+void buf_close(struct msgbuf *, struct buf *);
void buf_free(struct buf *);
void msgbuf_init(struct msgbuf *);
void msgbuf_clear(struct msgbuf *);