In addition, if I am not mistaken (I could not find it on the man pages), :: recv with flags == 0 is equivalent to :: read (analogue to :: write and :: send)
Yes, this is correct if the file descriptor is a socket: send / recv will not work otherwise with EBADF.
And it is also true that in the connection-oriented model, send equivalent to sendto and recv - recvfrom with NULL sockaddr * , because the protocol already provides them.
In UDP, however, there is no connection, so the call is:
does not make sense, since the destination is not provided (EDESTADDRREQ). Instead, when you read the package, you know where it comes from, and you can use this IP address in case something looks wrong for istance.
My advice:
- Use
send / recv if you are in connection-oriented mode, for example. TCP - Use
sendto / recvfrom mainly for connectionless connections like UDP - Use
write / read if you do not specify a flag for raw I / O (the above functions may be considered higher)
I would not recommend a single class that handles both protocols, but rather two specialized ones; do not mix protocols.
source share