-
September 12th, 2005, 06:29 AM
#1
Select() problem in FD_SET
I am writing a multiserver program.
I use I/O mutiplexing (SELECT function).
I am going to use one read set (rset_1) of file descriptor for clients, and another set (rset_2) for server, so as to distinguish connection between client and server.
I want to ask how sould I combine these 2 sets in select function?
select(maxfd + 1, &allset, 0,0,0);
or should I call select function twice?
select(maxfd + 1, &rset_1, 0,0,0);
if ( FD_ISSET(listenfd, &rset_1 ) )
{.......}
select(maxfd + 1, &rset_2, 0,0,0);
if ( FD_ISSET(listenfd, &rset_2 ) )
{.......}
However, as I know, select function is blocking and cannot be called twice, am I right??
-
September 12th, 2005, 07:43 AM
#2
Re: Select() problem in FD_SET
I want to ask how sould I combine these 2 sets in select function?
select(maxfd + 1, &allset, 0,0,0);
or should I call select function twice?
select(maxfd + 1, &rset_1, 0,0,0);
if ( FD_ISSET(listenfd, &rset_1 ) )
{.......}
select(maxfd + 1, &rset_2, 0,0,0);
if ( FD_ISSET(listenfd, &rset_2 ) )
{.......}
You have to call
Code:
FD_SET(s, *set)
Adds descriptor s to set.
Twice to insert your socket descriptor into your fd_set .
if u have a client socket then call FD_SET(s,&rset_1) and if have a server descriptor then call FD_SET(s,&rset_2).
here i assume that u have want to handle two groups of socket some are called client sockets and some are called server sockets.
A Person who is polite is given goodness and a person who is away from Politeness is away from Goodness.
NAUMAAN
-
September 12th, 2005, 09:25 AM
#3
Re: Select() problem in FD_SET
thank you for your reply and I know that 2 different FD SET should be used for client and server.
however, if I am in the case that I am waiting for either connection of client and server, how should I implement the SELECT function?
-
September 12th, 2005, 11:50 AM
#4
Re: Select() problem in FD_SET
What exactly do you want to achieve? Is it a server listening on multiple ports and serving multiple clients at a time?
If yes, simply add all sockets (server and client) to one read-set. Thjis way you would get notified if the clients send data to the server as well as when a new connection request might be accepted.
HTH
Richard
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|