Advertisement

select() question

Started by December 21, 2003 07:49 PM
1 comment, last by zackriggle 21 years, 1 month ago
There is something that I cannot find in MSDN about select(). When the function returns, how do I know which sockets are readable\writeable? Are the fd_set things changed so that only the readable\writeable ones are still in the fd_set structures? i.e.

// Variables

fd_set   s;
SOCKET   sock;
TIMEVAL  timeout;

// Set Timeout

timeout.tv_sec = 0;
timeout.tv_usec = 100;

// Set the fd_ shizzlenit

FD_ZERO(&s);
FD_SET(sock,&s);

// Call select

select(0,&s,NULL,NULL,&timeout);

if( FD_ISSET(sock,&s) )
{
  // Read from socket

}
when select() returns, it modifys the set so that only those with readable/writable/errors are contained in there respective sets.

So in your example, s would have only the sockets with waiting data on them.
Michael BartmanCEO, Lead ProgrammerDark Omen Studios
Advertisement
Thanks, that''s what I thought.

This topic is closed to new replies.

Advertisement