summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/imsg.c
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-01-01 23:09:10 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-01-01 23:09:10 +0000
commitb0fe3d62ce222a08711e8e5b1baac92a3a38274f (patch)
tree32de7a4f9362cf82034eac9437c4cf7d6cc00ab3 /usr.sbin/bgpd/imsg.c
parent6cabb1abe96ce74073c96812753fe62daa7f8a68 (diff)
now that imsg_get uses bigger buffers, one read call can put more than one
imsg into the buffer. since imsg_get by definition only returns one imsg we missed the next imsg(s) until the next poll event on the socket in question, building up a queue on that socket. didn't show up as a problem yet... factor out imsg_read, which reads into the buffer. imsg_get now entirely operates on the buffers and does not read(2) itself. make all callers cope by calling imsg_read on poll events and calling imsg_get in a loop until all imsgs are processed.
Diffstat (limited to 'usr.sbin/bgpd/imsg.c')
-rw-r--r--usr.sbin/bgpd/imsg.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/usr.sbin/bgpd/imsg.c b/usr.sbin/bgpd/imsg.c
index ed80e399c45..5201c8fc353 100644
--- a/usr.sbin/bgpd/imsg.c
+++ b/usr.sbin/bgpd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.14 2003/12/30 22:42:31 henning Exp $ */
+/* $OpenBSD: imsg.c,v 1.15 2004/01/01 23:09:09 henning Exp $ */
/*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@@ -35,10 +35,9 @@ imsg_init(struct imsgbuf *ibuf, int sock)
}
int
-imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
+imsg_read(struct imsgbuf *ibuf)
{
- ssize_t n, datalen = 0;
- size_t av, left;
+ ssize_t n;
if ((n = read(ibuf->sock, ibuf->r.buf + ibuf->r.wpos,
sizeof(ibuf->r.buf) - ibuf->r.wpos)) == -1) {
@@ -52,10 +51,22 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
logit(LOG_CRIT, "imsg_get: pipe close");
return (-1);
}
- av = ibuf->r.wpos + n;
+
+ ibuf->r.wpos += n;
+
+ return (0);
+}
+
+int
+imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
+{
+ ssize_t datalen = 0;
+ size_t av, left;
+
+ av = ibuf->r.wpos;
if (IMSG_HEADER_SIZE > av)
- return (-1);
+ return (0);
memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr));
if (imsg->hdr.len < IMSG_HEADER_SIZE ||
@@ -64,7 +75,7 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
return (-1);
}
if (imsg->hdr.len > av)
- return (-1);
+ return (0);
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
if ((imsg->data = malloc(datalen)) == NULL) {