TutSocketRecvAll


Name

TutSocketRecvAll — read multiple times from a socket until all data has been received

Synopsis

T_INT4 TutSocketRecvAll(fd, buf, size, flags) 
T_INT4 fd; 
T_PTR buf; 
T_INT4 size; 
T_INT4 flags; 

Arguments

fd — socket file descriptor to read from

buf — buffer to put data into

size — number of bytes to read

flags — flags for recv

Return Values

Number of bytes read if successful, -1 otherwise.

Diagnostics

If TutSocketRecvAll fails, it returns -1 and sets the global SmartSockets error number to one of:

Description

TutSocketRecvAll is a convenience function that keeps reading data from a socket until the desired number of bytes have been read, an error occurs, or EOF is reached. Unlike files, sockets can have data broken up into smaller packets for transmission over a network, and thus multiple reads are often necessary to allow time for all packets to arrive at the destination.

This function call normally blocks until size bytes have been read from socket. This behavior can be modified by setting the block mode using TutSocketSetBlockMode. The function TutSocketCheck can be used to determine if data is available to be read before calling TutSocketRecvAll.

The flags argument can be any flags accepted by the recv function. Refer to your operating system manuals for full information on these flags. Specify 0 for flags to use the default behavior.

Caution

None

See Also

TutSocketRecvTimeout, TutSocketCheck, TutSocketSetBlockMode

Examples

This example shows how to check if the desired number of bytes are read with TutSocketRecvAll:

bytes_read = TutSocketRecvAll(socket, buf, size, 0); 
if (bytes_read != size) { 
  /* error */ 
} 

TIBCO SmartSockets™ Utilities
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com