Skip to content
Snippets Groups Projects
Commit 6827b801 authored by Timothe Jost's avatar Timothe Jost
Browse files

readUdp able to timeout from a revcmsg

parent 30040e73
No related branches found
No related tags found
No related merge requests found
......@@ -207,6 +207,18 @@ void *readUdp(void *arg)
socklen_t len = sizeof(r_addr);
struct sockaddr recv_addr;
// Set a timeout for the recvfrom function
struct timeval timeout;
timeout.tv_sec = 2; // 5 seconds timeout
timeout.tv_usec = 0;
if (setsockopt(udp_sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0)
{
perror("setsockopt failed");
SHOULD_EXIT = 1;
return NULL;
}
for (;;)
{
......@@ -216,12 +228,22 @@ void *readUdp(void *arg)
printf("Controller message recieved %s\n", bytes_read);
processSmcp1Request(buffer, &recv_addr, bytes_read);
}
else if (bytes_read < 0 && PROXY_INIT_COMPLETE)
else if (bytes_read < 0)
{
perror("recvfrom failed");
printf("ERROR : UDP-SOCKET COMMUNICATION FAILED, CLOSING PROGRAM\n");
SHOULD_EXIT = 1;
break;
if (errno == EWOULDBLOCK || errno == EAGAIN)
{
// printf("recvfrom timeout, no data received.\n");
}
else
{
perror("recvfrom failed");
if (PROXY_INIT_COMPLETE)
{
printf("ERROR : UDP-SOCKET COMMUNICATION FAILED, CLOSING PROGRAM\n");
SHOULD_EXIT = 1;
break;
}
}
}
if (SHOULD_EXIT && PROXY_INIT_COMPLETE)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment