I am porting a socket based application from Linux to Windows CE 6.0. I came across a line of code which was setting the socket option for Receive Timeout.
struct timeval timeout = 200;
timeout.tv_usec = 200000;
setsockopt(mySock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, (socklen_t) sizeof(timeout));
I searched for possible porting implementations and could find these two threads relevant. setsockopt() with RCVTIMEO is not working in windows mobile5 and Set timeout for winsock recvfrom
After setting the receive timeout as 200ms, there is a call to recv() for receiving data from the remote IP(sender). The first link explained clearly to spawn off a thread and wait on it but 200ms looked too less for my case as the sender sends for ~10 sec. The second link's select() suggestion is what I added to my code but the behavior is very inconsistent. Sometimes it receives no packets, sometimes 1 or sometimes more. But the existing implementation works fine on Linux.
Am I doing the porting right way? Can anyone point out a probable mistake or make a suggestion?
Thanks!