… | |
… | |
25 | similar functions, as well as less rarely ones such as C<mknod>, C<futime> |
25 | similar functions, as well as less rarely ones such as C<mknod>, C<futime> |
26 | or C<readlink>. |
26 | or C<readlink>. |
27 | |
27 | |
28 | It also offers wrappers around C<sendfile> (Solaris, Linux, HP-UX and |
28 | It also offers wrappers around C<sendfile> (Solaris, Linux, HP-UX and |
29 | FreeBSD, with emulation on other platforms) and C<readahead> (Linux, with |
29 | FreeBSD, with emulation on other platforms) and C<readahead> (Linux, with |
30 | emulation elsewhere>). |
30 | emulation elsewhere). |
31 | |
31 | |
32 | The goal is to enable you to write fully non-blocking programs. For |
32 | The goal is to enable you to write fully non-blocking programs. For |
33 | example, in a game server, you would not want to freeze for a few seconds |
33 | example, in a game server, you would not want to freeze for a few seconds |
34 | just because the server is running a backup and you happen to call |
34 | just because the server is running a backup and you happen to call |
35 | C<readdir>. |
35 | C<readdir>. |
… | |
… | |
104 | This callback is invoked when libeio detects that all pending requests |
104 | This callback is invoked when libeio detects that all pending requests |
105 | have been handled. It is "edge-triggered", that is, it will only be |
105 | have been handled. It is "edge-triggered", that is, it will only be |
106 | called once after C<want_poll>. To put it differently, C<want_poll> and |
106 | called once after C<want_poll>. To put it differently, C<want_poll> and |
107 | C<done_poll> are invoked in pairs: after C<want_poll> you have to call |
107 | C<done_poll> are invoked in pairs: after C<want_poll> you have to call |
108 | C<eio_poll ()> until either C<eio_poll> indicates that everything has been |
108 | C<eio_poll ()> until either C<eio_poll> indicates that everything has been |
109 | handled or C<done_poll> has been called, which signals the same. |
109 | handled or C<done_poll> has been called, which signals the same - only one |
|
|
110 | method is needed. |
110 | |
111 | |
111 | Note that C<eio_poll> might return after C<done_poll> and C<want_poll> |
112 | Note that C<eio_poll> might return after C<done_poll> and C<want_poll> |
112 | have been called again, so watch out for races in your code. |
113 | have been called again, so watch out for races in your code. |
113 | |
114 | |
|
|
115 | It is quite common to have an empty C<done_call> callback and only use |
|
|
116 | the return value from C<eio_poll>, or, when C<eio_poll> is configured to |
|
|
117 | handle all outstanding replies, it's enough to call C<eio_poll> once. |
|
|
118 | |
114 | As with C<want_poll>, this callback is called while locks are being held, |
119 | As with C<want_poll>, this callback is called while locks are being held, |
115 | so you I<must not call any libeio functions form within this callback>. |
120 | so 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 | |
119 | This function has to be called whenever there are pending requests that |
124 | This function has to be called whenever there are pending requests that |
120 | need finishing. You usually call this after C<want_poll> has indicated |
125 | need 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 | |
186 | For most other event loops, you would typically use a pipe - the event |
191 | For most other event loops, you would typically use a pipe - the event |
… | |
… | |
290 | |
295 | |
291 | Cancel the request (and all its subrequests). If the request is currently |
296 | Cancel the request (and all its subrequests). If the request is currently |
292 | executing it might still continue to execute, and in other cases it might |
297 | executing it might still continue to execute, and in other cases it might |
293 | still take a while till the request is cancelled. |
298 | still take a while till the request is cancelled. |
294 | |
299 | |
295 | Even if cancelled, the finish callback will still be invoked - the |
300 | When cancelled, the finish callback will not be invoked. |
296 | callbacks of all cancellable requests need to check whether the request |
|
|
297 | has been cancelled by calling C<EIO_CANCELLED (req)>: |
|
|
298 | |
|
|
299 | static int |
|
|
300 | my_eio_cb (eio_req *req) |
|
|
301 | { |
|
|
302 | if (EIO_CANCELLED (req)) |
|
|
303 | return 0; |
|
|
304 | } |
|
|
305 | |
|
|
306 | In addition, cancelled requests will I<either> have C<< req->result >> |
|
|
307 | set to C<-1> and C<errno> to C<ECANCELED>, or I<otherwise> they were |
|
|
308 | successfully executed, despite being cancelled (e.g. when they have |
|
|
309 | already been executed at the time they were cancelled). |
|
|
310 | |
301 | |
311 | C<EIO_CANCELLED> is still true for requests that have successfully |
302 | C<EIO_CANCELLED> is still true for requests that have successfully |
312 | executed, as long as C<eio_cancel> was called on them at some point. |
303 | executed, as long as C<eio_cancel> was called on them at some point. |
313 | |
304 | |
314 | =back |
305 | =back |
… | |
… | |
788 | #TODO |
779 | #TODO |
789 | |
780 | |
790 | void eio_grp_limit (eio_req *grp, int limit); |
781 | void eio_grp_limit (eio_req *grp, int limit); |
791 | |
782 | |
792 | |
783 | |
793 | =back |
|
|
794 | |
|
|
795 | |
784 | |
796 | =head1 LOW LEVEL REQUEST API |
785 | =head1 LOW LEVEL REQUEST API |
797 | |
786 | |
798 | #TODO |
787 | #TODO |
799 | |
788 | |