1

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?

2
  • Generally, I'd anticipate a code bug. Can you paste in your FD_SET and your select calls please? Commented Nov 9, 2009 at 8:44
  • I think your response to 1) might be causing 2). What is your response to 1)? Posting your code would help. Commented Nov 9, 2009 at 13:34

3 Answers 3

2

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);
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.