--- libeio/eio.pod 2011/07/13 21:31:40 1.23 +++ libeio/eio.pod 2013/03/11 07:59:41 1.34 @@ -27,7 +27,7 @@ It also offers wrappers around C (Solaris, Linux, HP-UX and FreeBSD, with emulation on other platforms) and C (Linux, with -emulation elsewhere>). +emulation elsewhere). The goal is to enable you to write fully non-blocking programs. For example, in a game server, you would not want to freeze for a few seconds @@ -47,21 +47,24 @@ =head2 FORK SUPPORT -Calling C is fully supported by this module - but you must not -rely on this. It is currently implemented in these steps: - - 1. wait till all requests in "execute" state have been handled - (basically requests that are already handed over to the kernel). - 2. fork - 3. in the parent, continue business as usual, done - 4. in the child, destroy all ready and pending requests and free the - memory used by the worker threads. This gives you a fully empty - libeio queue. - -Note, however, since libeio does use threads, the above guarantee doesn't -cover your libc, for example, malloc and other libc functions are not -fork-safe, so there is very little you can do after a fork, and in fact, -the above might crash, and thus change. +Usage of pthreads in a program changes the semantics of fork +considerably. Specifically, only async-safe functions can be called after +fork. Libeio uses pthreads, so this applies, and makes using fork hard for +anything but relatively fork + exec uses. + +This library only works in the process that initialised it: Forking is +fully supported, but using libeio in any other process than the one that +called C is not. + +You might get around by not I libeio before (or after) forking in +the parent, and using it in the child afterwards. You could also try to +call the L function again in the child, which will brutally +reinitialise all data structures, which isn't POSIX conformant, but +typically works. + +Otherwise, the only recommendation you should follow is: treat fork code +the same way you treat signal handlers, and only ever call C in +the process that uses it, and only once ever. =head1 INITIALISATION/INTEGRATION @@ -81,6 +84,9 @@ It accepts two function pointers specifying callbacks as argument, both of which can be C<0>, in which case the callback isn't called. +There is currently no way to change these callbacks later, or to +"uninitialise" the library again. + =item want_poll callback The C callback is invoked whenever libeio wants attention (i.e. @@ -172,7 +178,7 @@ ev_idle_init (&repeat_watcher, repeat); ev_async_init (&ready_watcher, ready); - ev_async_start (loop &watcher); + ev_async_start (loop, &watcher); eio_init (want_poll, 0); } @@ -229,13 +235,17 @@ =back +Members not explicitly described as accessible must not be +accessed. Specifically, there is no guarantee that any members will still +have the value they had when the request was submitted. + The return value of the callback is normally C<0>, which tells libeio to continue normally. If a callback returns a nonzero value, libeio will stop processing results (in C) and will return the value to its caller. -Memory areas passed to libeio must stay valid as long as a request -executes, with the exception of paths, which are being copied +Memory areas passed to libeio wrappers must stay valid as long as a +request executes, with the exception of paths, which are being copied internally. Any memory libeio itself allocates will be freed after the finish callback has been called. If you want to manage all memory passed to libeio yourself you can use the low-level API. @@ -588,6 +598,13 @@ Calls C. If the syscall is missing, then the call is emulated by simply reading the data (currently in 64kiB chunks). +=item eio_syncfs (int fd, int pri, eio_cb cb, void *data) + +Calls Linux' C syscall, if available. Returns C<-1> and sets +C to C if the call is missing I, +if the C is C<< >= 0 >>, so you can probe for the availability of the +syscall with a negative C argument and checking for C<-1/ENOSYS>. + =item eio_sync_file_range (int fd, off_t offset, size_t nbytes, unsigned int flags, int pri, eio_cb cb, void *data) Calls C. If the syscall is missing, then this is the same @@ -615,7 +632,7 @@ =item eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) -Reads (C) or modifies (C) or modifies (C) the given memory area, page-wise, that is, it reads (or reads and writes back) the first octet of every page that spans the memory area. @@ -709,7 +726,7 @@ Left alone, a group request will instantly move to the pending state and will be finished at the next call of C. -There usefulness stems from the fact that, if a subrequest is added to a +The usefulness stems from the fact that, if a subrequest is added to a group I a call to C, via C, then the group will not finish until all the subrequests have finished. @@ -740,27 +757,27 @@ =item 2) open the file, maybe Next, open the file with C and add the request to the group -request and you are finished steting up the request. +request and you are finished setting up the request. If, for some reason, you cannot C (path is a null ptr?) you -cna set C<< grp->result >> to C<-1> to signal an error and let the gorup +can set C<< grp->result >> to C<-1> to signal an error and let the group request finish on its own. =item 3) open callback adds more requests In the open callback, if the open was not successful, copy C<< -req->errorno >> to C<< grp->errorno >> and set C<< grp->errorno >> to +req->errorno >> to C<< grp->errorno >> and set C<< grp->result >> to C<-1> to signal an error. Otherwise, malloc some memory or so and issue a read request, adding the read request to the group. -=item 4) continue issuign requests till finished +=item 4) continue issuing requests till finished -In the real callback, check for errors and possibly continue with +In the read callback, check for errors and possibly continue with C or any other eio request in the same way. -As soon as no new requests are added the group request will finish. Make +As soon as no new requests are added, the group request will finish. Make sure you I set C<< grp->result >> to some sensible value. =back @@ -773,8 +790,6 @@ void eio_grp_limit (eio_req *grp, int limit); -=back - =head1 LOW LEVEL REQUEST API @@ -911,10 +926,8 @@ requests, you might want to increase this. If this symbol is undefined (the default) then libeio will use its default -stack size (C currently). If it is defined, but -C<0>, then the default operating system stack size will be used. In all -other cases, the value must be an expression that evaluates to the desired -stack size. +stack size (C currently). In all other cases, the +value must be an expression that evaluates to the desired stack size. =back