<< Previous | Index | Next >>

sock_fastread


int sock_fastread( tcp_Socket *s, byte *dp, int len );

Description

Reads up to len bytes from dp on socket s. If possible this function fills the buffer, otherwise only the number of bytes immediately available, if any, are returned.

Starting with Dynamic C 7.05, this function is only valid for TCP sockets. For UDP sockets, use udp_recv() or udp_recvfrom(). Prior to 7.05, this function cannot be used on UDP sockets after sock_recv_init() is called.

Parameters

s

Pointer to a socket.

dp

Buffer to put bytes that are read.

len

Maximum number of bytes to write to the buffer.

Return Value

0: Success, number of bytes read.
-1: Error.

Library

TCP.LIB (Prior to DC 7.05, this was DCRTCP.LIB)

See Also

sock_read, sock_fastwrite, sock_write, sockerr, udp_recv, udp_recvfrom, sock_xfastwrite, sock_aread, sock_axread

Example

Note that sock_fastread() and sock_read() do not necessarily return a complete or single line; they return blocks of bytes. In comparison, sock_getc() returns a single byte at a time and thus yields poor performance.


do {
/* this function does not block */
len = sock_fastread(s, buffer, sizeof(buffer)-1);
if (len>0) {
buffer[len] = 0;
printf("%s", buffer);
}
} while(tcp_tick(s));


TCP/IP Manual
Vol 1
<<Previous | Index | Next>> rabbit.com