Are the C functions recvfrom and sendto mutually exclusive?
Are the C functions recvfrom and sendto mutually exclusive?
Not. Both of them can be executed by different threads at the same time.
sendto()
does not wait recvfrom()
to read data. It will put the data into the socket buffer and return. Several sendto()
may block to complete the previous one sendto()
. If any error occurs (buffer full, message is too large, etc.) while submitting, you can check validation errno
to check the reason for the failure. Basically, you don't need to synchronize between calls sendto()
and recvfrom()
from two threads; they are atomic operations.
source to share