Re: [CODE] "New Connection" code.

From: Daniel Koepke (dkoepke@california.com)
Date: 02/15/99


Andrew Ritchie wrote:

>       if (select(mother_desc + 1, &input_set, (fd_set *) 0,
> (fd_set *) 0, NULL) < 0) {
>         if (errno == EINTR)                    <-
>           log("Waking up to process signal."); <-
>         else                                   <-
>           perror("Select coma");               <-
>       } else                                   <-
>         log("New connection.  Waking up.");    <-
>       gettimeofday(&last_time, (struct timezone *) 0);
>     }
>
> I'm a bit stuck on this code. I'm not quite sure how it works,
> around the lines indicated with a "<-". It seems to me one of
> three things can happen in the if..else statement. Why is this?
> Somehow it skips the entire section.

Actually, it's not skipping the entire section. What you are
experiencing is exactly how the code is supposed to operate and is
a result of select() blocking (thanks to the last parameter,
the time to wait, being NULL). The code doesn't go beyond that
point until select() returns (with an error or otherwise), which
it doesn't until there's an error or the read set changes (and,
since we have no other players, a change in the read set would
mean we have a new connection).

So, really, the only part of the code you didn't understand is what
select() does. You might find "man select" helpful -- although
probably not; if you're going to be changing any of the socket code,
make sure that you understand it inside and out. Buy a book,
probably one of Stevens's (_UNIX_Network_Programming_ or some
such), read it. Alternatively: stare at the code, try to comprehend
the man pages, and stare at the code some more.

-dak


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST