...
This compliant solution performs the recv() call with the parameter oMSG_nonblockDONTWAIT, which causes the call to fail if no messages are available on the socket:
| Code Block | ||||
|---|---|---|---|---|
| ||||
void thread_foo(void *ptr) {
uint32_t num;
int result;
/* sock is a connected TCP socket */
if ((result = recv(sock, (void *)&num, sizeof(uint32_t), OMSG_NONBLOCKDONTWAIT)) < 0) {
/* Handle Error */
}
if ((result = pthread_mutex_lock(&mutex)) != 0) {
/* Handle Error */
}
/* ... */
if ((result = pthread_mutex_unlock(&mutex)) != 0) {
/* Handle Error */
}
}
|
...