Previous topic |
Next topic |
Contents |
Contact z/OS |
Library |
PDF
recvfrom() z/OS Communications Server: IP Sockets Application Programming Interface Guide and Reference SC27-3660-00 |
|
The recvfrom() call receives data on a socket by name with descriptor s and stores it in a buffer. The recvfrom() call applies to any datagram socket, whether connected or unconnected. For a datagram socket, when name is nonzero, the source address of the message is filled. Parameter namelen must first be initialized to the size of the buffer associated with name; then it is modified on return to indicate the actual size of the address stored there. This call returns the length of the incoming message or data. If a datagram packet is too long to fit in the supplied buffer, datagram sockets discard extra bytes. If data is not available for the socket s, and s is in blocking mode, the recvfrom() call blocks the caller until data arrives. If data is not available, and s is in nonblocking mode, recvfrom() returns a -1 and sets errno to EWOULDBLOCK. See fcntl() or ioctl() to set nonblocking mode. For datagram sockets, this call returns the entire datagram sent, providing the datagram can fit into the specified buffer. Stream sockets act like streams of information with no boundaries separating data. For example, if applications A and B are connected with a stream socket, and Application A sends 1000 bytes, each call to this function can return 1 byte, or 10 bytes, or the entire 1000 bytes. Therefore, applications using stream sockets should place this call in a loop, calling this function until all data has been received. For datagram protocols, recvfrom() returns the source address associated with each incoming datagram. For connection-oriented protocols like TCP, getpeername() returns the address associated with the remote end of the connection.
Return valuesIf successful, the length
of the message or datagram is returned in bytes. The
value 0 indicates that the connection is closed. The value -1 indicates
an error. Errno identifies the specific error.
Related callsfcntl(), getsockopt(), ioctl(), read(), readv(), recv(), recvmsg(), select(), selectex(), send(), sendmsg(), sendto(), setsockopt(), socket(), write(), writev() |
Copyright IBM Corporation 1990, 2014
|