what means the highest socket desc argument on select

hi,
i'm new to socket programming. for the select API in socket programming the 1st agrument is an integer and its highest socket desc + 1. How to find the highest socket desc ? cos in my program more than 100 clients are connceted, i'm applying select on any on those clients. Can any one explain what exactly it means?

int select( /* returns number active */
int nfds, /* highest desc used + 1 */
fd_set *read, /* Await read on these */
fd_set *write, /* await write on these */
fd_set *except, /* seldom used */
struct timeval *timeout /* inactivity timeout */
)

i want to know what nfds is doing and what value i should use ?
It's platform dependent. POSIX systems use file descriptors as sockets, so the numbers are low. Windows doesn't have built in sockets, but uses winsock2. The socket numbers are high, but that doesn't matter. FD_SET, FS_ZERO, select should still work. If you can't make a small program that reproduces the problem, I can't help you.
here is the code..


read()
{

FD_ZERO(&rfds);
for (int i=3;i<10;i++) // assume i the the list of socket desc i've
{
FD_SET(i,&rfds);
}
int rc= select (maxSock+1, &rfds,0,0,&timeout); // here is my confusion.what is the value that
//i've to use in maxSock.
if ( rc > 0)
{
for ( int i=3; i<10;1++)
{
if ( FD_ISSET(i,&rfds)
recv(i,buff,100,0);
}
}
}

kindly explain me...

}
If the file descriptors you put in the read set (rfds) are, for example, 4, 6, 8, and 10, then
the first parameter to select should be the highest of those four values plus one. eg, 10 + 1 == 11.
That's not really a complete example, assumptions have to be made about what you've done.

Here's a site that explains it. If you're still stuck, I'll do my best to help.
http://www.lowtek.com/sockets/select.html
Topic archived. No new replies allowed.