If the server is not sending a line feed at the end of its message, chances are you will block, because
fgets() won't return until error or end of file or buffer has been completely filled or a line feed is encountered, whichever occurs first.
But beyond that, just on general principle, you shouldn't mix
fgets() with
select(), because
fgets() works at a higher level (of buffering). If you're going to use
select(), then use
read() instead.
Another problem, which may be contributing to your symptoms, is that you need to reset the file descriptor set each time through the loop. The safest way is to reset it completely each time, thus:
Code:
FD_ZERO(&rx_set);
FD_SET(sock,&rx_set);
This should appear just before the
select() call, each time through the loop.
Also, what's the value of
tv? (TV is worthless, but I'm not talking about that here.) If you don't want timeout at all, but instead want to wait forever for something to happen, don't say
&tv; say
NULL instead.
If you want to return immediately instead of waiting, set the fields of
tv to zero.
If you use
&tv (whether zero or nonzero), you must set the value of
tv each time through the loop, just before
select(), just like
rx_set.
Before continuing, please please please do this, and read the page carefully:
Hope this helps.