I am guessing the socket is blocking.
int noblock(int fd)
{
int flags = fcntl(fd, F_GETFL, 0);
if (flags < 0) return 0;
flags = (blocking) ? (flags&~O_NONBLOCK) : (flags|O_NONBLOCK);
return (fcntl(fd, F_SETFL, flags) == 0) ? 1 : 0;
}
Use this to set the socket to non-blocking. When there is no data to read, recv()
will return a -1
and set errno
to EWOULDBLOCK
See if those changes get you past your current problem.
You really should be checking the return codes of all you calls