Download Network Enabler SDK 2 API Reference
Transcript
Network Enabler SDK 2 API Reference recvfrom API Reference receive a datagram and store the source address Data Input/Output Syntax #include <sdksock.h> int recvfrom ( int s, char *buf, int len, int flags, SOCKADDR *from, int *fromlen ); Arguments s buf len flags from fromlen a descriptor identifying a bound socket a buffer for the incoming data the length of buf specifies the way in which the call is made an optional pointer to a buffer which will hold the source address upon return an optional pointer to the size of the from buffer Description This function is used to read incoming data on a (possibly connected) socket and capture the address from which the data was sent. For sockets of type SOCK_STREAM, all information currently available up to the size of the buffer supplied is returned. The from and fromlen parameters are ignored for SOCK_STREAM sockets. For datagram sockets, data is extracted from the first enqueued datagram, up to the size of the buffer supplied. If the datagram is larger than the buffer supplied, the buffer is filled with the first part of the message, and the excess data is lost. If from is non-zero, and the socket is of type SOCK_DGRAM, the network address of the peer which sent the data is copied to the corresponding SOCKADDR. The value pointed to by fromlen is initialized to the size of this structure, and is modified on return to indicate the actual size of the address stored there. If no incoming data is available at the socket, the recvfrom() call waits for data to arrive unless the socket is non-blocking. In this case a value of -1 is returned with the error code set to EWOULDBLOCK. The select() calls may be used to determine when more data arrives. If the socket is of type SOCK_STREAM and the remote side has shut down the connection gracefully or the connection has been reset, a recvfrom() will complete immediately with 0 bytes received. flags may be used to influence the behavior of the function invocation beyond the options specified for the associated socket. That is, the semantics of this function are determined by the socket options and the flags parameter. The latter is constructed by “or-ing” any of the following values: Value MSG_OOB Meaning read out-of-band data (SOCK_STREAM only) Return Value If there are no errors, recvfrom() returns the number of bytes received. If the connection has been closed, it returns 0. Otherwise, it returns -1, and the global variable errno will contain one of the following values. 3-33