From: Stephen D. <sd...@gm...> - 2006-01-06 19:18:38
|
On 1/6/06, Zoran Vasiljevic <zv...@ar...> wrote: > > Am 04.01.2006 um 20:40 schrieb Stephen Deasey: > > > On 1/4/06, Vlad Seryakov <vl...@cr...> wrote: > >> I believe poll can be used on any file descriptor, not only sockets. > >> > > > > It doesn't work if the file descriptor is backed by a file on disk. > > If it did, we wouldn't have to talk about aio_read() :-) > > > > > > Hmmm... > > SYNOPSIS > #include <poll.h> > > int > poll(struct pollfd *fds, nfds_t nfds, int timeout); > > DESCRIPTION > Poll() examines a set of file descriptors to see if some of > them are > ready for I/O or if certain events have occurred on them. The > fds argu- > ment is a pointer to an array of pollfd structures as defined > in <poll.h> > (shown below). The nfds argument determines the size of the > fds array. > > I believe that poll should work with files as well. That is I can't > find no reason why it shoudn't by reading the man and inspecting > the "poll" emulation we have in nsd/unix.c. Tcl also uses the similar > machinery to implement non-blocking read/write to files (see below). > > The AIO comes into place where you basically have one more layer > of processing in the kernel which handles your dispatched events > and let you asynchronously inspect them, cancel them etc. > > So: poll + tcl_event_loop *=3D AIO. Unfortunately this works only > for single-threaded apps as tcl_event_loop only handles events > from the current thread. Roughly. As AIO is normally done by the > kernel it is/shouldbe much more faster. > One can always simulate the aio by a specialized thread and non-blocking > read/writing. But having this all done for you in the kernel (as > in some "proper" implementation) things should be simpler to implement > and faster in deployment. > Don't believe everything you read. Man pages are often little more than hopes and dreams... In practice poll() does not work with files backed by disk. Even the Open Group specifies that "Regular files always poll TRUE for reading and writing." http://www.opengroup.org/onlinepubs/007908799/xsh/poll.html Make sure you've read the C10K page: http://www.kegel.com/c10k.html |