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:

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;
}
After calling the above function, however, my socket seems to be a in non-blocking mode.

Code:
int result = recv(s, data+offset, size, 0);
Returns "s is nonblocking and recv() would block"

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