tags:

views:

191

answers:

3

Inside the read FD_SET I have several sockets:

  1. the main socket listening for new connections
  2. accepted sockets listening for incoming data.

I set the timeout for 30 seconds and called select(). I quickly noticed the behavior is different for each:

  1. When a new client connects on the listening port, it returns immediately from blocking.
  2. When an already connected client sends a message, it blocks for the entire 30 seconds.

Is there a way I can make it return immediately in the second case?

A: 

I constantly use such select()s without any problem.

Probably you do something wrong with accepted sockets waiting on data. Could you please post code fragment? Especially most important is how you set first select() parameter.

Roman Nikitchenko
+2  A: 

My guess is either you aren't including all your sockets in the correct fd_set or you aren't passing in the highest numbered file descriptor plus 1 as the first parameter (nfds below) to the select call.

select(nfds, &readfds, &writefds, &execptfds, &timeout);
Bob
A: 

One of the most common errors with select(2) is not re-initializing fd_sets before calling select() again.

Nikolai N Fetissov