* Alexander Farber <[EMAIL PROTECTED]> [2005-08-05 19:36]:
> I'm trying to move an iterative server (a small multiplayer card game)
> from using select() to poll()  (BTW is it a good idea at all?)

yes, it is a good idea. poll is easier to use and as a bonus a bit more 
efficient.

> So it is important for me that none of the reads/writes/accepts block.

so use nonblocking sockets...

        int     flags;

        if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
                fatal("fnctl F_GETFL");

        flags |= O_NONBLOCK;

        if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
                fatal("fnctl F_SETFL");


> My question is, what events should I poll() ? With select() it is easy -

>     1) read/write returns > 0 means ok
>     2) read/write returns = 0 means connection closed
>     3) read/write returns < 0 means connection interrupted

that is true no matter what.
actually your case #3 is not completely - on error they return -1 and 
only -1, with errno set.

> If I poll() for POLLIN/POLLOUT, will the read/write ever block?

could, unless you use nonblocking sockets.

> Do I need to poll() for POLLHUP and/or POLLERR to detect
> closed or interrupted connections or is POLLIN enough and it
> is same as 2) and 3) above?

the latter.
bgpd's session.c session_main() and dispatch_msg might be worth a read.

-- 
BS Web Services, http://www.bsws.de/
OpenBSD-based Webhosting, Mail Services, Managed Servers, ...
Unix is very simple, but it takes a genius to understand the simplicity.
(Dennis Ritchie)

Reply via email to