C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2006, 12:35 PM   #1
Registered User
 
Join Date: Nov 2005
Posts: 137
FD_ZERO and FD_SET.. i still don't get it

ok i know that select picks the sockets that are set, but do the sockets set themselves when they have information to be received?

i was told that in the begining of the loop to set all the sockets, but that doesn't really make much sense to me. i want to have a loop and it pick out sockets that have information to be received in it. can anyone tell me if i need to set the sockets before hand or if they become set when they have information. i also need to know if when i process the socket if i should FD_CLEAR it.
yahn is offline   Reply With Quote
Old 02-04-2006, 01:21 PM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,710
Something like
Code:
fd_set socketSet, selectSet;
// socketSet is the permanent list of sockets you want to monitor.
// having a separate variable saves a lot of FD_SET calls.

// just before calling select, do
selectSet = socketSet;
int rval = select ( maxFd+1, &selectSet, NULL, NULL, NULL );

// if rval > 0, then use FD_ISSET on the selectSet to see which particular sockets have something
// available for reading.
Salem is offline   Reply With Quote
Old 02-04-2006, 06:35 PM   #3
Registered User
 
Join Date: Nov 2005
Posts: 137
ok well that helps some but i still don't get the whole picture. when i accept a socket and i want to add it to the list what should i do? just FD_SET(sock, list_to_add_to)? whenever a message is sent to that socket is it FD_SET? how does select help any if if doesn't get set when it has something in it?
yahn is offline   Reply With Quote
Old 02-04-2006, 07:45 PM   #4
Registered User
 
Join Date: Apr 2005
Posts: 134
Check the link below

select()--Synchronous I/O Multiplexing
nkhambal is offline   Reply With Quote
Old 02-05-2006, 01:21 AM   #5
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,710
The bits you FD_SET in a set on input to select() will be those things you want to watch.
When select returns, the set is modified to indicate which fd's have changed, and these you test with FD_ISSET.
Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 05:40 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22