The sendmsg method sends a message to the peer side.
On success, sendmsg returns the actual size of message that has just been sent. The size should be equal to len. Otherwise UDT::ERROR is returned and specific error information can be retrieved by getlasterror. If UDT_SNDTIMEO is set to a positive value, zero will be returned if the message cannot be sent before the timer expires.
Error Name | Error Code | Comment |
ECONNLOST | 2001 | connection has been broken. |
ENOCONN | 2002 | u is not connected. |
EINVSOCK | 5004 | u is not an valid socket. |
ESTREAMILL | 5009 | cannot use sendmsg in SOCK_STREAM mode. |
ELARGEMSG | 5012 | the message is too large to be hold in the sending buffer. |
SASYNCSND | 6001 | u is non-blocking (UDT_SNDSYN = false) but no buffer space is available. |
ETIMEOUT | 6003 | Timeout on UDT_SNDTIMEO . |
The sendmsg method sends a message to the peer side. The UDT socket must be in SOCK_DGRAM mode in order to send or receive messages. Message is the minimum data unit in this situation. In particular, sendmsg always tries to send the message out as a whole, that is, the message will either to completely sent or it is not sent at all.
In blocking mode (default), sendmsg waits until there is enough space to hold the whole message. In non-blocking mode, sendmsg returns immediately and returns error if no buffer space available.
If UDT_SNDTIMEO is set and the socket is in blocking mode, sendmsg only waits a limited time specified by UDT_SNDTIMEO option. If there is still no buffer space available when the timer expires, error will be returned. UDT_SNDTIMEO has no effect for non-blocking socket.
The ttl parameter gives the message a limited life time, which starts counting once the first packet of the message is sent out. If the message has not been delivered to the receiver after the TTL timer expires and each packet in the message has been sent out at least once, the message will be discarded. Lost packets in the message will be retransmitted before TTL expires.
On the other hand, the inorder option decides if this message should be delivered in order. That is, the message should not be delivered to the receiver side application unless all messages prior to it are either delivered or discarded.
Finally, if the message size is greater than the size of the receiver buffer, the message will never be received in whole by the receiver side. Only the beginning part that can be hold in the receiver buffer may be read and the rest will be discarded.