Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-30-2005, 07:45 AM   #1
LQ Newbie
Registered: Oct 2005
Distribution: slackware
Posts: 5

Rep: Reputation: 0
question about select sys call

hello people

lets say that i want to use the select sys call as in the example


while(1){ //let's say that this is the server main loop

select(10, &rdf , NULL , NULL , NULL) ; //waiting select for reading from rdf set

if(FD_ISSET(fd1,&rdf)){ //let's say that fd1 has data for reading

.... //code here
} //end of loop

after the select returns (so we have something to read from... let's say fd1 as in example)
do i have to re-add the fd's (fd1,fd2,fd3,fd4) in the rdf set before the main loop ends(in the question mark) or there is no problem so i don't add anything in the above piece of code?

Old 10-30-2005, 10:22 AM   #2
Registered: Oct 2005
Location: Chicago, USA
Distribution: Slackware & Fedora
Posts: 66

Rep: Reputation: 15
First off, dont forget to zero out the fd set:
FD_ZERO( &rdf );

Because you are a server, you might want to consider checking the return value of select (it can error).

To answer your question: yes, you would have to reconstruct the fd sets because the select operation will alter the sets pointed to. The zeroing can be done once, but you may want to re-SET the fds you want and CLR the ones you don't on subsequent calls.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C sockets Select call when to use? cranium2004 Programming 1 03-14-2005 06:56 AM
Write sys call failing ppy Programming 1 11-05-2004 09:57 AM
Any sys call to list all users ? dileepkk Linux - General 5 07-06-2004 07:04 PM
Kill sys call eshwar_ind Programming 4 05-07-2004 12:41 PM
any sys call to get ip address of NIC jmdey Linux - General 2 05-30-2002 04:09 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:33 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration