buffer i/o using read(2) on BSD sockets

Don Libes libes at cme.nist.gov
Tue Mar 6 09:41:06 AEST 1990


In article <637 at lot.ACA.MCC.COM> ables at lot.ACA.MCC.COM (King Ables) writes:
>I want to read an arbitrarily large block of data and not have to worry
>about message boundaries (hence read/write rather than send/recv).
>
>This works fine on a socket connected between two processes on my Sun up
>to a buffer size of 4096.  Anything after that doesn't seem to make it.
>I get (for example) 8000 back from write(hd, buf, n) where n=8000, but
>when I read(hd, buf, 8000) I get 4096 and a successive read(2) returns -1.

Well, what's the value of errno?  Note that expecting to be able to
read arbitrarily-large packets is unrealistic due to limited kernel
buffering and protocol design.

I know you don't want to encapsulate your I/O, but that is the only
solution.  I have some code that does it which you can anonymously ftp
from durer.cme.nist.gov as pub/sized_io.shar.Z

I also wrote a paper describing some of these problems.  It is
"Packet-Oriented Communications Using a Stream Protocol --or-- Making
TCP/IP on Berkeley UNIX a Little More Pleasant to Use", NISTIR
90-4232, January 1990" and is available from:

Mary Lou Fahey
NIST
Bldg 220, Rm A-127
Gaithersburg, MD  20899
fahey at cme.nist.gov

Don Libes          libes at cme.nist.gov      ...!uunet!cme-durer!libes



More information about the Comp.unix.wizards mailing list