LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 10-30-2005, 06:45 AM   #1
xatzipol
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

FD(fd1,&rdf);
FD(fd2,&rdf);
FD(fd3,&rdf);
FD(fd4,&rdf);

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?

thanks
 
Old 10-30-2005, 09:22 AM   #2
naf
Member
 
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.
 
  


Reply


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 05:56 AM
Write sys call failing ppy Programming 1 11-05-2004 08:57 AM
Any sys call to list all users ? dileepkk Linux - General 5 07-06-2004 06:04 PM
Kill sys call eshwar_ind Programming 4 05-07-2004 11:41 AM
any sys call to get ip address of NIC jmdey Linux - General 2 05-30-2002 03:09 PM


All times are GMT -5. The time now is 01:19 AM.

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