Are the C functions recvfrom and sendto mutually exclusive?

I have one thread calling recvfrom

with 100ms timeout in a loop. Another thread calls periodically sendto

.

Whether the function sendto

stays on until recvfrom

released by a timeout (or successful read) or sends data within that time period.

+3


source to share


2 answers


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.

+3


source


No, it doesn’t wait (at least it doesn’t wait any longer than it takes to provide streaming access to the comms stack).



+1


source







All Articles