PDA

View Full Version : Select() and time


x33
04-08-2003, 11:14 PM
Hi!
I've got another question... There may be replies on the subject in this forum, but i haven't noticed any...
Imagine we've got a 'classical' select() loop of this kind:

while (true)
{
do_select();
perform_check_and_properly_process_the_situation() ;
}

Now what if some of the socket descriptors change their state during the second operation ('perform_check_and_properly_process_the_situation ()')? Will select() know about it on the next while-loop iteration? Or the changes won't be noticed?

Uzume
04-09-2003, 09:38 AM
select() should detect the changes in any descriptors state because it essentially is polling the state of the descriptors (and optionally blocking until an event arrives).

x33
04-09-2003, 10:17 AM
Well, actually that's not what i was asking of...
Imagine we call a select() and detect some changes in the read_fd_set. Then we should proceed and process the incoming data (whatever it is). Now what happens if new data arrives during the processing of the data previously received? Will select know about it when the 'while' loop enters its next iteration (the next select() call)? Or will the new data be unnoticed? If it won't be caught, then we cannot be sure that all of the data is processed... Or am I misunderstanding something?

RobSeace
04-09-2003, 01:24 PM
I think Uzume accurately answered that question... When you call
select(), it will check the current state of the FDs, and immediately
return if appropriate... Ie: if the socket still has data to read when
you call select(), then select() will still find the socket readable... So,
yes, your situation should be handled fine... (Assuming your processing
part is only reading the first data that arrived, and NOT clearing out all
data it sees, of course! If your read out data that arrives after select()
noticed the socket became readable, then of course select() can't notice
that new data, because you've already removed it, so it's no longer
readable...)