CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005
    Posts
    18

    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??

  2. #2
    Join Date
    Dec 2002
    Location
    St.Louis MO, USA
    Posts
    672

    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

  3. #3
    Join Date
    Sep 2005
    Posts
    18

    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?

  4. #4
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    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
  •  





Click Here to Expand Forum to Full Width

Featured