I have one thread calling
recvfrom with a timeout of 100 ms in a loop. Another thread calls
sendto function wait until the
recvfrom is released by the timeout (or a successful read) or does it send the data during that period of time.
Best How To :
Are the C functions recvfrom and sendto mutually exclusive?
No. They can both be executed by different threads at the same time.
sendto() doesn't wait for
recvfrom() to read the data. It would place the data into the socket's buffer and return. Multiple
sendto() may block for the previous
sendto() to complete. If any error occurred (buffer full, message too big etc) while sending then you can check inspect
errno to check the cause of failure. Basically, you don't need to do any synchronization between
recvfrom() calls from the two threads; they are atomic operations.