![]() |
|
| << Previous | Index | Next >> | |
| | |
int sock_read( tcp_Socket *s, byte *dp, int len );
Description
Reads up to
lenbytes fromdpon sockets. This function will busy wait until eitherlenbytes are read or there is an error condition. Ifsock_yield()has been called, the user-defined function that is passed to it will be called in a tight loop whilesock_read()is busy waiting.Starting with Dynamic C 7.05, this function is only valid for TCP sockets. For UDP sockets, use
udp_recv()orudp_recvfrom(). Prior to 7.05, this function cannot be used on UDP sockets aftersock_recv_init()is called.Parameters
s
- Pointer to a socket.
dp
- Buffer to store 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
Example
Note that
sock_fastread()andsock_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 {
len = sock_bytesready(s);
if (len > 0) {
if (len > sizeof( buffer) - 1) // If too many bytes, read some
len = sizeof( buffer ) - 1; // now, read the rest next time.
sock_read( s, buffer, len);buffer[len] = 0;
printf( "%s", buffer);
}
} while ( tcp_tick(s));
| TCP/IP Manual Vol 1 |
<<Previous | Index | Next>> | rabbit.com |