Article View: comp.sys.sun
Article #12183FIONREAD on datagram internet sockets?
From: Neil Hunt
Date: Mon, 24 Apr 1989 20:01
Date: Mon, 24 Apr 1989 20:01
34 lines
1658 bytes
1658 bytes
Does anyone know anything about the missing 16 bytes are which are
reported by ioctl(sock, FIONREAD, &n) when applied to an internet datagram
socket? I find that if ioctl reports N bytes available on the socket,
then a read with a much larger buffer returns a maximum of N-16 bytes. If
there are multiple datagrams, with lengths N0, N1, ...Nn, then N = N0 + N1
+ ... + Nn + 16, and after packet n has been read, (theoretically leaving
16 bytes, according to the original report) the next read blocks, and an
additional ioctl(sock, FIONREAD, &n) performed at that point reports 0
bytes available.
Here is the code, which is supposed never to block:
(Error checks removed for clarity.)
read_last(sock, packet, len)
char *packet;
{
ioctl(sock, FIONREAD, &n);
while(n > 0)
{
i = read(sock, packet, len);
n -= i;
}
return i;
}
A workaround is easy. I was curious whether this is a bug, or if it is
just a case of not finding the right page in the manual (is there such a
thing as a right page in ``Socket Based IPC Tutorial''?)
PS: The system in question is a Sun 2/120, 3.5; also Sun 2/50, 3.5.
Neil/.
Technical Details
Message-ID:
<8904050232.AA06898@wayback.teleos.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!rice!sun-spots-requestShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!rice!sun-spots-request From: Neil%Teleos.com@ai.sri.com (Neil Hunt) Newsgroups: comp.sys.sun Subject: FIONREAD on datagram internet sockets? Keywords: SunOS Message-ID: <8904050232.AA06898@wayback.teleos.com> Date: 24 Apr 89 20:01:21 GMT Sender: usenet@rice.edu Organization: Sun-Spots Lines: 34 Approved: Sun-Spots@rice.edu Original-Date: Tue, 4 Apr 89 19:32:57 PDT X-Sun-Spots-Digest: Volume 7, Issue 244, message 5 of 10