From owner-freebsd-hackers Sat Feb 22 18:43:07 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id SAA09750 for hackers-outgoing; Sat, 22 Feb 1997 18:43:07 -0800 (PST) Received: from mail13.digital.com (mail13.digital.com [192.208.46.30]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id SAA09745 for ; Sat, 22 Feb 1997 18:43:02 -0800 (PST) Received: from muggsy.lkg.dec.com by mail13.digital.com (8.7.5/UNX 1.5/1.0/WV) id VAA08385; Sat, 22 Feb 1997 21:37:35 -0500 (EST) Received: from usr602.zko.dec.com by muggsy.lkg.dec.com (5.65/DEC-Ultrix/4.3) with SMTP id AA28893; Sat, 22 Feb 1997 21:37:31 -0500 Message-Id: <3.0.32.19970222213738.006a1cb0@netrix.lkg.dec.com> X-Sender: popmatt@netrix.lkg.dec.com X-Mailer: Windows Eudora Pro Version 3.0 Demo (32) Date: Sat, 22 Feb 1997 21:37:46 -0500 To: Terry Lambert From: Matt Thomas Subject: Re: Alternatives to SYSV IPC? Cc: hackers@FreeBSD.ORG Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >The length field would not be necessary if the framing were enforced >by the transport: a receive into a buffer larger than the maximum >allowable message type that could be framed for any given transmitter >state would be sufficient. You do a recv into the buffer, then you >dispatch based on a field dereference from the newly acquired data >(probably a type field), and dispatch the data for processing from >a big switch statement. No additional recv's necessary. This can be done today with the BSD4.4 socket framework. With AF_LOCAL (AF_UNIX) sockets and the use of MSG_EOR with send() and MSG_WAITALL with recvmsg() it does work. I've attached a small example program (which works under FreeBSD 2.1.0 and Digital UNIX 4.0). #include #include #include #include #include int main( int argc, void **argv) { int fds[2]; struct msghdr msg; char buf[20]; struct iovec iov[1]; int cc; if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) perror("socketpair"); if (send(fds[1], "Hi ", 3, MSG_EOR) < 0) perror("send"); if (send(fds[1], "There", 5, MSG_EOR) < 0) perror("send"); close(fds[1]); bzero(&msg, sizeof(msg)); iov[0].iov_base = buf; iov[0].iov_len = sizeof(buf); msg.msg_iov = iov; msg.msg_iovlen = 1; for (;;) { cc = recvmsg(fds[0], &msg, 0); if (cc <= 0) break; buf[cc] = '\0'; printf("%d: %s%s", cc, buf, msg.msg_flags & MSG_EOR ? " (EOR)\n" : ""); } if (cc < 0) perror("recvmsg"); putchar('\n'); } -- Matt Thomas Internet: matt@3am-software.com 3am Software Foundry WWW URL: http://www.3am-software.com/bio/matt.html Westford, MA Disclaimer: I disavow all knowledge of this message