ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libeio/eio.pod
(Generate patch)

Comparing libeio/eio.pod (file contents):
Revision 1.27 by root, Sun Jul 24 03:32:54 2011 UTC vs.
Revision 1.36 by root, Sun Jan 24 16:36:20 2016 UTC

25similar functions, as well as less rarely ones such as C<mknod>, C<futime> 25similar functions, as well as less rarely ones such as C<mknod>, C<futime>
26or C<readlink>. 26or C<readlink>.
27 27
28It also offers wrappers around C<sendfile> (Solaris, Linux, HP-UX and 28It also offers wrappers around C<sendfile> (Solaris, Linux, HP-UX and
29FreeBSD, with emulation on other platforms) and C<readahead> (Linux, with 29FreeBSD, with emulation on other platforms) and C<readahead> (Linux, with
30emulation elsewhere>). 30emulation elsewhere).
31 31
32The goal is to enable you to write fully non-blocking programs. For 32The goal is to enable you to write fully non-blocking programs. For
33example, in a game server, you would not want to freeze for a few seconds 33example, in a game server, you would not want to freeze for a few seconds
34just because the server is running a backup and you happen to call 34just because the server is running a backup and you happen to call
35C<readdir>. 35C<readdir>.
104This callback is invoked when libeio detects that all pending requests 104This callback is invoked when libeio detects that all pending requests
105have been handled. It is "edge-triggered", that is, it will only be 105have been handled. It is "edge-triggered", that is, it will only be
106called once after C<want_poll>. To put it differently, C<want_poll> and 106called once after C<want_poll>. To put it differently, C<want_poll> and
107C<done_poll> are invoked in pairs: after C<want_poll> you have to call 107C<done_poll> are invoked in pairs: after C<want_poll> you have to call
108C<eio_poll ()> until either C<eio_poll> indicates that everything has been 108C<eio_poll ()> until either C<eio_poll> indicates that everything has been
109handled or C<done_poll> has been called, which signals the same. 109handled or C<done_poll> has been called, which signals the same - only one
110method is needed.
110 111
111Note that C<eio_poll> might return after C<done_poll> and C<want_poll> 112Note that C<eio_poll> might return after C<done_poll> and C<want_poll>
112have been called again, so watch out for races in your code. 113have been called again, so watch out for races in your code.
113 114
115It is quite common to have an empty C<done_call> callback and only use
116the return value from C<eio_poll>, or, when C<eio_poll> is configured to
117handle all outstanding replies, it's enough to call C<eio_poll> once.
118
114As with C<want_poll>, this callback is called while locks are being held, 119As with C<want_poll>, this callback is called while locks are being held,
115so you I<must not call any libeio functions form within this callback>. 120so you I<must not call any libeio functions from within this callback>.
116 121
117=item int eio_poll () 122=item int eio_poll ()
118 123
119This function has to be called whenever there are pending requests that 124This function has to be called whenever there are pending requests that
120need finishing. You usually call this after C<want_poll> has indicated 125need finishing. You usually call this after C<want_poll> has indicated
176 { 181 {
177 loop = EV_DEFAULT; 182 loop = EV_DEFAULT;
178 183
179 ev_idle_init (&repeat_watcher, repeat); 184 ev_idle_init (&repeat_watcher, repeat);
180 ev_async_init (&ready_watcher, ready); 185 ev_async_init (&ready_watcher, ready);
181 ev_async_start (loop &watcher); 186 ev_async_start (loop, &watcher);
182 187
183 eio_init (want_poll, 0); 188 eio_init (want_poll, 0);
184 } 189 }
185 190
186For most other event loops, you would typically use a pipe - the event 191For most other event loops, you would typically use a pipe - the event
233 238
234The C<void *data> member simply stores the value of the C<data> argument. 239The C<void *data> member simply stores the value of the C<data> argument.
235 240
236=back 241=back
237 242
243Members not explicitly described as accessible must not be
244accessed. Specifically, there is no guarantee that any members will still
245have the value they had when the request was submitted.
246
238The return value of the callback is normally C<0>, which tells libeio to 247The return value of the callback is normally C<0>, which tells libeio to
239continue normally. If a callback returns a nonzero value, libeio will 248continue normally. If a callback returns a nonzero value, libeio will
240stop processing results (in C<eio_poll>) and will return the value to its 249stop processing results (in C<eio_poll>) and will return the value to its
241caller. 250caller.
242 251
243Memory areas passed to libeio must stay valid as long as a request 252Memory areas passed to libeio wrappers must stay valid as long as a
244executes, with the exception of paths, which are being copied 253request executes, with the exception of paths, which are being copied
245internally. Any memory libeio itself allocates will be freed after the 254internally. Any memory libeio itself allocates will be freed after the
246finish callback has been called. If you want to manage all memory passed 255finish callback has been called. If you want to manage all memory passed
247to libeio yourself you can use the low-level API. 256to libeio yourself you can use the low-level API.
248 257
249For example, to open a file, you could do this: 258For example, to open a file, you could do this:
286 295
287Cancel the request (and all its subrequests). If the request is currently 296Cancel the request (and all its subrequests). If the request is currently
288executing it might still continue to execute, and in other cases it might 297executing it might still continue to execute, and in other cases it might
289still take a while till the request is cancelled. 298still take a while till the request is cancelled.
290 299
291Even if cancelled, the finish callback will still be invoked - the 300When cancelled, the finish callback will not be invoked.
292callbacks of all cancellable requests need to check whether the request
293has been cancelled by calling C<EIO_CANCELLED (req)>:
294
295 static int
296 my_eio_cb (eio_req *req)
297 {
298 if (EIO_CANCELLED (req))
299 return 0;
300 }
301
302In addition, cancelled requests will I<either> have C<< req->result >>
303set to C<-1> and C<errno> to C<ECANCELED>, or I<otherwise> they were
304successfully executed, despite being cancelled (e.g. when they have
305already been executed at the time they were cancelled).
306 301
307C<EIO_CANCELLED> is still true for requests that have successfully 302C<EIO_CANCELLED> is still true for requests that have successfully
308executed, as long as C<eio_cancel> was called on them at some point. 303executed, as long as C<eio_cancel> was called on them at some point.
309 304
310=back 305=back
626 621
627=over 4 622=over 4
628 623
629=item eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data) 624=item eio_mtouch (void *addr, size_t length, int flags, int pri, eio_cb cb, void *data)
630 625
631Reads (C<flags == 0>) or modifies (C<flags == EIO_MT_MODIFY) the given 626Reads (C<flags == 0>) or modifies (C<flags == EIO_MT_MODIFY>) the given
632memory area, page-wise, that is, it reads (or reads and writes back) the 627memory area, page-wise, that is, it reads (or reads and writes back) the
633first octet of every page that spans the memory area. 628first octet of every page that spans the memory area.
634 629
635This can be used to page in some mmapped file, or dirty some pages. Note 630This can be used to page in some mmapped file, or dirty some pages. Note
636that dirtying is an unlocked read-write access, so races can ensue when 631that dirtying is an unlocked read-write access, so races can ensue when
760request finish on its own. 755request finish on its own.
761 756
762=item 3) open callback adds more requests 757=item 3) open callback adds more requests
763 758
764In the open callback, if the open was not successful, copy C<< 759In the open callback, if the open was not successful, copy C<<
765req->errorno >> to C<< grp->errorno >> and set C<< grp->errorno >> to 760req->errorno >> to C<< grp->errorno >> and set C<< grp->result >> to
766C<-1> to signal an error. 761C<-1> to signal an error.
767 762
768Otherwise, malloc some memory or so and issue a read request, adding the 763Otherwise, malloc some memory or so and issue a read request, adding the
769read request to the group. 764read request to the group.
770 765
771=item 4) continue issuing requests till finished 766=item 4) continue issuing requests till finished
772 767
773In the real callback, check for errors and possibly continue with 768In the read callback, check for errors and possibly continue with
774C<eio_close> or any other eio request in the same way. 769C<eio_close> or any other eio request in the same way.
775 770
776As soon as no new requests are added the group request will finish. Make 771As soon as no new requests are added, the group request will finish. Make
777sure you I<always> set C<< grp->result >> to some sensible value. 772sure you I<always> set C<< grp->result >> to some sensible value.
778 773
779=back 774=back
780 775
781=head4 REQUEST LIMITING 776=head4 REQUEST LIMITING
783 778
784#TODO 779#TODO
785 780
786void eio_grp_limit (eio_req *grp, int limit); 781void eio_grp_limit (eio_req *grp, int limit);
787 782
788
789=back
790 783
791 784
792=head1 LOW LEVEL REQUEST API 785=head1 LOW LEVEL REQUEST API
793 786
794#TODO 787#TODO
922This symbol governs the stack size for each eio thread. Libeio itself 915This symbol governs the stack size for each eio thread. Libeio itself
923was written to use very little stackspace, but when using C<EIO_CUSTOM> 916was written to use very little stackspace, but when using C<EIO_CUSTOM>
924requests, you might want to increase this. 917requests, you might want to increase this.
925 918
926If this symbol is undefined (the default) then libeio will use its default 919If this symbol is undefined (the default) then libeio will use its default
927stack size (C<sizeof (void *) * 4096> currently). If it is defined, but 920stack size (C<sizeof (void *) * 4096> currently). In all other cases, the
928C<0>, then the default operating system stack size will be used. In all
929other cases, the value must be an expression that evaluates to the desired 921value must be an expression that evaluates to the desired stack size.
930stack size.
931 922
932=back 923=back
933 924
934 925
935=head1 PORTABILITY REQUIREMENTS 926=head1 PORTABILITY REQUIREMENTS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines