TCP socket using BSD recv() (WIN/TCP for VMS)

John F Nixon jnixon at andrew.ATL.GE.COM
Tue Mar 20 10:42:26 AEST 1990


TAYBENGH%NUSDISCS.BITNET at cunyvm.cuny.edu writes:
>        I faced the similar problem as King when I used BSD recv() provided by
>WIN/TCP for VMS Release 3.2. The maximum size received is only 4K for TCP.
>But one thing puzzled me is I always get 1K in the very first recv() call,
>only then I receive the remaining data, if the buffer size sent > 1K. For
>example, if the client sends 5K of data, then the server's first recv() call
>get 1K, and the second recv() will get the remaining 4K.


It sounds like you are using SOCK_STREAM sockets.  The semantics of
SOCK_STREAM are such that you are *not* guaranteed to receive all the
bytes of a write with a single read (especially with "large" writes).
You are responsible for maintaining record boundaries with SOCK_STREAM
sockets.  Either write fixed size records (usually not advisable), or
prepend a size field to your records.  Then read in a loop till all
of the data arrives.  Pseudo-code is:

	/* record size in recsize */
	byteshere = 0;
	while ( byteshere < recsize ) {
		bytes = read (soc, buf + byteshere, recsize - byteshere);
		if ( bytes < 0 ) {
			error stuff...
		}

		byteshere += bytes;
	}

You get the idea...

--
		
----
jnixon at atl.ge.com                    ...steinmetz!atl.decnet!jnxion



More information about the Comp.unix.wizards mailing list