- A non-block UDP socket called "connect" and use "send" to send data, is it necessary to use "select/epoll/kqueue" to test whether it is writable? 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? Or that's unnecessary, because it just sends data out and does not care about whether the recv buff of the side is full? If that's true, the "send" may only return success unless the other side is down?
- For the UDP socket, what's the return value of "send", for example, I send 100 bytes, it may only return -1(error) or 100, no other value? For TCP may return 50 ~~~~
-
UDP is connectionless - the sender has no idea if the packet even made it to the receiver, much less whether they accepted it or whether the buffer was full.Jonathon Reinhart– Jonathon Reinhart2017-04-11 10:50:07 +00:00Commented Apr 11, 2017 at 10:50
2 Answers
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