tfRecvFromTo
Table of Contents >> Programmer's Reference
| #include <trsocket.h> |
| int tfRecvFromTo | ( |
| int socketDescriptor, | |
| char * bufferPtr, | |
| int bufferLength, | |
| int flags, | |
| struct sockaddr * fromAddressPtr, | |
| int * addressLengthPtr, | |
| struct sockaddr * toAddressPtr | |
| ); |
Function Description
tfRecvFromTo() behaves the same as recvfrom() except for the use of the parameter toAddressPointer. This parameter specifies the address to which data was sent. tfRecvFromTo() is used to receive messages from another socket. tfRecvFromTo() may be used to receive data on a socket whether it is in a connected state or not, but not on a TCP socket. socketDescriptor is a socket created with socket. If fromAddressPtr is not a NULL pointer, the source address of the message is filled in. If toAddressPtr is not a NULL pointer, the destination address of the message is filled in. addressLengthPtr is a value-result parameter, initialized to the size of the buffer associated with fromAddressPtr, and with toAddressPtr, and modified on return to indicate the actual size of the address stored there. The length of the message is returned. If a message is too long to fit in the supplied buffer, excess bytes may be discarded depending on the type of socket the message is received from (see socket()). If no messages are available at the socket, the receive call waits for a message to arrive, unless the socket is non-blocking, or the MSG_DONTWAIT flag is set in the flags parameter, in which case -1 is returned with socket error being set to EWOULDBLOCK. select() may be used to determine when more data arrives, or/and when out-of-band data arrives. tfRegisterSocketCB() may be used to asynchronously determine when more data arrives or/and when out-of-band data arrives.
Parameters
- socketDescriptor
- The socket descriptor to use to receive the data.
- bufferPtr
- The buffer to store the received data.
- bufferLength
- The length of the buffer to store the received data.
- flags
- MSG_DONTWAIT: Don't wait for the data.
- 0: Wait for the data to arrive.
- fromAddressPtr
- Where to store the address the data came from.
- addressLengthPtr
- Length of the area point to by fromAddressPtr or toAddressPtr.
- toAddressPtr
- A pointer to the location to store the address the data was sent to.
Returns
- >= 0
- Success.
- TM_SOCKET_ERROR
- Failure.
| TM_SOCKET_ERROR means that this socket call has failed and the errorCode has been set on the socket itself.
To retrieve the socket error the user must call tfGetSocketError(socketDescriptor). |
Possible socket errors
- TM_EBADF
- 'socketDescriptor' is not a valid descriptor.
- TM_ENOBUFS
- Insufficient memory to complete the operation.
- TM_EMSGSIZE
- The message was too long.
- TM_EPROTOTYPE
- The TCP protocol requires usage of recv() not tfRecvFromTo().
- TM_EWOULDBLOCK
- The socket is marked as non-blocking and the tfRecvFromTo() operation would block.