Reputation: 232
Upvotes: 1
Views: 454
Reputation: 137398
In general, send()
will not block, and always return the number of bytes written, unless the local (sending) buffer in the kernel is full. For a UDP socket that will basically never happen. For a TCP socket that will happen if you write faster than the link or receiving side can handle.
Upvotes: 0
Reputation: 1
In the case, the other side recv buffer is full, "send" may fail, so i can use "select" to test that it's writable so that "send" may return success ?
You're using UDP. The packet gets sent, and if the receive buffer is full on the receiving end, the receiving system will just drop it. Read this: https://en.wikipedia.org/wiki/User_Datagram_Protocol#Reliability_and_congestion_control_solutions
The result of the send()
call will be completely independent of the state of the receiver. It will return success even if the receive side doesn't exist.
See this for how UDP handles datagrams larger than the underlying network's packet size: UDP Sockets on Linux; send successfully but unable to receive large buffer
Upvotes: 2