Subject: Re: THW game is ready to be included on the system
To: None <netbsd-users@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: netbsd-users
Date: 07/05/2006 04:36:57
In article <20060705035001.GA29880@us270-gl0.eradman.com>,
Eric Radman  <theman@eradman.com> wrote:
>On 04:30 Mon 03 Jul     , Noud deBrouwer wrote:
>> plz. point me the model-boundries we have now.
>
>I finally took the time to demonstrate my point, but instead I proved
>myself wrong. The code in the less essential src/games does NOT always
>point to the best way of doing things. For example, the tetris included
>with netbsd-1-6 uses the select() function in input.c:
>
>i = 1;
>switch (select(1, (fd_set *)&i, (fd_set *)0, (fd_set *)0, s)) {
>
>}
>
>This uses a bitwise operation for the fd_set field even though the man
>page in every version of NetBSD describes the use of FD_ZERO and FD_SET
>instead, largely because that is less implementation-dependant. These
>macros are good. In OpenBSD this was corrected so that it looks like
>this:
>
>fd_set fds;
>
>FD_ZERO(&fds);
>FD_SET(STDIN_FILENO, &fds);
>switch (select(STDIN_FILENO + 1, &fds, (fd_set *)0, (fd_set *)0, s)) {
>
>}
>
>The other thing I noticed is that nowhere in the source for tetris is
><sys/select.h> included. This has traditionally be defined in
><sys/time.h>, but it should probably be change to use select.h so that
>it conforms to POSIX standards.
>
>So what did happen?
>
>From netbsd-1-6 to netbsd-2 select() was replaced with poll():
>
>#include <sys/poll.h>
>
>struct pollfd set[1];
>
>set[0].fd = STDIN_FILENO;
>set[0].events = POLLIN;
>switch (poll(set, 1, s->tv_sec * 1000 + s->tv_usec / 1000)) {
>
>}
>
>Okay, that's fine, but there's nothing wrong with select(), is there?
>Reading the CVS changelog leaves the impression that poll() preferred,
>and thereby avoids demonstrating a simple, correct usage of select().
>
>I officially retract my previous assertion that this is "model" code.
>It is code that mostly works, so Claudio, I'm all for a new and improved
>version of worm after it's been tested in pkgsrc. Does anyone else
>concur?

poll and specially pollts is always superior to select from both
a performance and reporting granularity.

christos