tfSendToFrom
Table of Contents >> Programmer's Reference
#include <trsocket.h> |
int tfSendToFrom | ( |
int socketDescriptor, | |
const char * bufferPtr, | |
int bufferLength, | |
int flags, | |
const struct sockaddr * toAddressPtr, | |
int addressLength, | |
const struct sockaddr * fromAddressPtr | |
); |
Function Description
tfSendToFrom() behaves the same as sendto() except for the use of the parameter fromAddressPointer. This parameter specifies the address from where data is to be sent. tfSendToFrom() is used to transmit a message to another transport end-point. tfSendToFrom() may be used at any time (either in a connected or unconnected state), but not for a TCP socket. socketDescriptor is a socket created with socket. The address of the target is given by toAddressPtr, with addressLength specifying its size. If the message is too long to pass atomically through the underlying protocol, then TM_SOCKET_ERROR is returned with the socket error being set to TM_EMSGSIZE, and the message is not transmitted. A return value of TM_SOCKET_ERROR indicates locally detected errors only. A positive return value does not implicitly mean the message was delivered, but rather that it was sent. If the socket does not have enough buffer space available to hold the message being sent, and is in blocking mode, tfSendToFrom() blocks. If it is in non-blocking mode or the MSG_DONTWAIT flag has been set in the flags parameter, TM_SOCKET_ERROR is returned with the socket error being set to TM_EWOULDBLOCK. The select call may be used to determine when it is possible to send more data.
Parameters
- socketDescriptor
- The socket descriptor to use to send the data.
- bufferPtr
- The buffer to send.
- bufferLength
- The length of the buffer to send.
- flags
- MSG_DONTWAIT: Don't wait for room in the socket send queue.
- 0: Wait for room in the socket send queue.
- toAddressPtr
- The address to send the data to.
- addressLength
- The length of the area pointed to by toAddressPtr or fromAddressPtr.
- fromAddressPtr
- The address to send the data from.
Returns
- >= 0
- The number of bytes actually sent on the socket.
- TM_SOCKET_ERROR
- Failure.
Note: | 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
- The socket descriptor is invalid.
- TM_EINVAL
- A parameter is invalid.
- TM_ENOBUFS
- Insufficient memory to complete the operation.
- TM_EHOSTUNREACH
- No route to destination. (For non-TCP sockets.)
- TM_ECONNREFUSED
- The socket received an ICMP destination unreachable message from the remote host. This typically means that the receiver is not listening on the remote port. (For non-TCP sockets.)
- TM_EMSGSIZE
- The message was too long.
- TM_EPROTOTYPE
- The TCP protocol requires usage of send() not tfSendToFrom().
- TM_EWOULDBLOCK
- The socket is marked as non-blocking and the tfSendToFrom() operation would block.