Results 1 to 1 of 1
I have some working C code, but I need to add some time outs to recv to handle to rare possibility that data is not returned. I am doing this ...
- 04-08-2009 #1Linux Newbie
- Join Date
- Aug 2005
- Location
- Sterling, VA
- Posts
- 100
Non-Blocking Socket?
I have some working C code, but I need to add some time outs to recv to handle to rare possibility that data is not returned. I am doing this as below:
After calling the above function, however, my socket seems to be a in non-blocking mode.Code:bool SetSocketTimeout(int timeout) { struct timeval time; time.tv_sec = timeout / 1000; time.tv_usec = (timeout % 1000) * 1000; if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&time, sizeof(time)) == -1) { return false; } return true; }
Returns "s is nonblocking and recv() would block"Code:int result = recv(s, data+offset, size, 0);
Am I making some obvious mistake? I can't imagine setting the SO_RCVTIMEO is supposed to put the socket in to non-blocking mode - that would defeat the entire purpose of a timeout.
Any help would be greatly appreciated.
Thank you,
Dave- EndianX -


Reply With Quote