Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix-wizards,net.wanted.sources Subject: Re: Need reliable datagrams Message-ID: <3719@umcp-cs.UUCP> Date: Mon, 6-Oct-86 22:30:26 EDT Article-I.D.: umcp-cs.3719 Posted: Mon Oct 6 22:30:26 1986 Date-Received: Wed, 8-Oct-86 07:06:56 EDT References: <3189@teddy.UUCP> Reply-To: chris@umcp-cs.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 91 Xref: mnetor net.unix-wizards:8173 net.wanted.sources:2392 In article <3189@teddy.UUCP> jpn@teddy.UUCP (John P. Nelson) writes: >I have an application that needs to reliably send packets of data >around among several tasks in a system. ... >My SUN manual lists a SOCK_SEQPACKET protocol as being "planned but >not implemented"; this looks like just what I need. Too bad. >We have all kinds of source licences here: BSD4.2, BSD4.3, ULTRIX 1.2, >and SUN 3.0. Any kind of pointers would be appreciated. While this works only under 4.3 systems, you can use AF_XNS sockets to send packets. SPP sockets are indeed SEQPACKET sockets. int s = socket(AF_XNS, SOCK_SEQPACKET, 0); if (s < 0) gripe(); You had best read the new IPC primer first. Alternatively, you can drop your own `packet' protocol on top of TCP: /* * Write a message packet. */ void wrmsg(fd, buf, size) int fd; char *buf; int size; { long nsize = htonl(size); /* * Could use writev here, for efficiency... */ if (write(fd, (char *) &nsize, sizeof (nsize)) != sizeof (nsize) || write(fd, buf, size) != size) gripe(); } /* * `reliable' read */ void rread(fd, buf, n) int fd; char *buf; int n; { int r; while (n > 0) { r = read(fd, buf, n); if (r <= 0) gripe(); buf += r; n -= r; } } int rdmsg(fd, buf, size) int fd; char *buf; int size; { long nsize, discard; char trash[BUFSIZ]; rread(fd, (char *) &nsize, sizeof (nsize)); nsize = ntohl(nsize); discard = nsize - size; if (nsize > size) nsize = size; size = nsize; rread(fd, buf, (int) nsize); while (discard > 0) { nsize = discard > BUFSIZ ? BUFSIZ : discard; nsize = read(fd, trash, (int) nsize); if (nsize <= 0) gripe(); discard -= nsize; } return (size); } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu