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

Comparing libeio/eio.pod (file contents):
Revision 1.17 by root, Tue Jul 5 18:59:28 2011 UTC vs.
Revision 1.18 by root, Tue Jul 5 20:34:42 2011 UTC

183to read that byte, and in the callback for the read end, you would call 183to read that byte, and in the callback for the read end, you would call
184C<eio_poll>. 184C<eio_poll>.
185 185
186You don't have to take special care in the case C<eio_poll> doesn't handle 186You don't have to take special care in the case C<eio_poll> doesn't handle
187all requests, as the done callback will not be invoked, so the event loop 187all requests, as the done callback will not be invoked, so the event loop
188will still signal readyness for the pipe until I<all> results have been 188will still signal readiness for the pipe until I<all> results have been
189processed. 189processed.
190 190
191 191
192=head1 HIGH LEVEL REQUEST API 192=head1 HIGH LEVEL REQUEST API
193 193
261 } 261 }
262 262
263 /* the first three arguments are passed to open(2) */ 263 /* the first three arguments are passed to open(2) */
264 /* the remaining are priority, callback and data */ 264 /* the remaining are priority, callback and data */
265 if (!eio_open ("/etc/passwd", O_RDONLY, 0, 0, file_open_done, 0)) 265 if (!eio_open ("/etc/passwd", O_RDONLY, 0, 0, file_open_done, 0))
266 abort (); /* something ent wrong, we will all die!!! */ 266 abort (); /* something went wrong, we will all die!!! */
267 267
268Note that you additionally need to call C<eio_poll> when the C<want_cb> 268Note that you additionally need to call C<eio_poll> when the C<want_cb>
269indicates that requests are ready to be processed. 269indicates that requests are ready to be processed.
270 270
271=head2 CANCELLING REQUESTS 271=head2 CANCELLING REQUESTS
272 272
273Sometimes the need for a request goes away before the request is 273Sometimes the need for a request goes away before the request is
274finished. In that case, one can cancel the reqiest by a call to 274finished. In that case, one can cancel the request by a call to
275C<eio_cancel>: 275C<eio_cancel>:
276 276
277=over 4 277=over 4
278 278
279=item eio_cancel (eio_req *req) 279=item eio_cancel (eio_req *req)
280 280
281Cancel the request. If the request is currently executing it might still 281Cancel the request (and all it's subrequests). If the request is currently
282continue to execute, and in other cases it might still take a while till 282executing it might still continue to execute, and in other cases it might
283the request is cancelled. 283still take a while till the request is cancelled.
284 284
285Even if cancelled, the finish callback will still be invoked - the 285Even if cancelled, the finish callback will still be invoked - the
286callbacks of all cancellable requests need to check whether the request 286callbacks of all cancellable requests need to check whether the request
287has been cancelled by calling C<EIO_CANCELLED (req)>: 287has been cancelled by calling C<EIO_CANCELLED (req)>:
288 288
291 { 291 {
292 if (EIO_CANCELLED (req)) 292 if (EIO_CANCELLED (req))
293 return 0; 293 return 0;
294 } 294 }
295 295
296In addition, cancelled requests will either have C<< req->result >> set to 296In addition, cancelled requests will I<either> have C<< req->result >>
297C<-1> and C<errno> to C<ECANCELED>, or otherwise they were successfully 297set to C<-1> and C<errno> to C<ECANCELED>, or I<otherwise> they were
298executed despite being cancelled (e.g. when they have already been 298successfully executed, despite being cancelled (e.g. when they have
299executed at the time they were cancelled). 299already been executed at the time they were cancelled).
300
301C<EIO_CANCELLED> is still true for requests that have successfully
302executed, as long as C<eio_cancel> was called on them at some point.
300 303
301=back 304=back
302 305
303=head2 AVAILABLE REQUESTS 306=head2 AVAILABLE REQUESTS
304 307
431=back 434=back
432 435
433=head3 READING DIRECTORIES 436=head3 READING DIRECTORIES
434 437
435Reading directories sounds simple, but can be rather demanding, especially 438Reading directories sounds simple, but can be rather demanding, especially
436if you want to do stuff such as traversing a diretcory hierarchy or 439if you want to do stuff such as traversing a directory hierarchy or
437processing all files in a directory. Libeio can assist thess complex tasks 440processing all files in a directory. Libeio can assist these complex tasks
438with it's C<eio_readdir> call. 441with it's C<eio_readdir> call.
439 442
440=over 4 443=over 4
441 444
442=item eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data) 445=item eio_readdir (const char *path, int flags, int pri, eio_cb cb, void *data)
534When this flag is specified, then the names will be returned in an order 537When this flag is specified, then the names will be returned in an order
535suitable for stat()'ing each one. That is, when you plan to stat() 538suitable for stat()'ing each one. That is, when you plan to stat()
536all files in the given directory, then the returned order will likely 539all files in the given directory, then the returned order will likely
537be fastest. 540be fastest.
538 541
539If both this flag and C<EIO_READDIR_DIRS_FIRST> are specified, then 542If both this flag and C<EIO_READDIR_DIRS_FIRST> are specified, then the
540the likely dirs come first, resulting in a less optimal stat order. 543likely directories come first, resulting in a less optimal stat order.
541 544
542=item EIO_READDIR_FOUND_UNKNOWN 545=item EIO_READDIR_FOUND_UNKNOWN
543 546
544This flag should not be specified when calling C<eio_readdir>. Instead, 547This flag should not be specified when calling C<eio_readdir>. Instead,
545it is being set by C<eio_readdir> (you can access the C<flags> via C<< 548it is being set by C<eio_readdir> (you can access the C<flags> via C<<
546req->int1 >>, when any of the C<type>'s found were C<EIO_DT_UNKNOWN>. The 549req->int1 >>, when any of the C<type>'s found were C<EIO_DT_UNKNOWN>. The
547absense of this flag therefore indicates that all C<type>'s are known, 550absence of this flag therefore indicates that all C<type>'s are known,
548which can be used to speed up some algorithms. 551which can be used to speed up some algorithms.
549 552
550A typical use case would be to identify all subdirectories within a 553A typical use case would be to identify all subdirectories within a
551directory - you would ask C<eio_readdir> for C<EIO_READDIR_DIRS_FIRST>. If 554directory - you would ask C<eio_readdir> for C<EIO_READDIR_DIRS_FIRST>. If
552then this flag is I<NOT> set, then all the entries at the beginning of the 555then this flag is I<NOT> set, then all the entries at the beginning of the
640 643
641 eio_custom (my_open, 0, my_open_done, "/etc/passwd"); 644 eio_custom (my_open, 0, my_open_done, "/etc/passwd");
642 645
643=item eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data) 646=item eio_busy (eio_tstamp delay, int pri, eio_cb cb, void *data)
644 647
645This is a a request that takes C<delay> seconds to execute, but otherwise 648This is a request that takes C<delay> seconds to execute, but otherwise
646does nothing - it simply puts one of the worker threads to sleep for this 649does nothing - it simply puts one of the worker threads to sleep for this
647long. 650long.
648 651
649This request can be used to artificially increase load, e.g. for debugging 652This request can be used to artificially increase load, e.g. for debugging
650or benchmarking reasons. 653or benchmarking reasons.
666There are two primary use cases for this: a) bundle many requests into a 669There are two primary use cases for this: a) bundle many requests into a
667single, composite, request with a definite callback and the ability to 670single, composite, request with a definite callback and the ability to
668cancel the whole request with its subrequests and b) limiting the number 671cancel the whole request with its subrequests and b) limiting the number
669of "active" requests. 672of "active" requests.
670 673
671Further below you will find more dicussion of these topics - first follows 674Further below you will find more discussion of these topics - first
672the reference section detailing the request generator and other methods. 675follows the reference section detailing the request generator and other
676methods.
673 677
674=over 4 678=over 4
675 679
676=item eio_req *grp = eio_grp (eio_cb cb, void *data) 680=item eio_req *grp = eio_grp (eio_cb cb, void *data)
677 681
748for example, in interactive programs, you might want to limit this time to 752for example, in interactive programs, you might want to limit this time to
749C<0.01> seconds or so. 753C<0.01> seconds or so.
750 754
751Note that: 755Note that:
752 756
757=over 4
758
753a) libeio doesn't know how long your request callbacks take, so the time 759=item a) libeio doesn't know how long your request callbacks take, so the
754spent in C<eio_poll> is up to one callback invocation longer then this 760time spent in C<eio_poll> is up to one callback invocation longer then
755interval. 761this interval.
756 762
757b) this is implemented by calling C<gettimeofday> after each request, 763=item b) this is implemented by calling C<gettimeofday> after each
758which can be costly. 764request, which can be costly.
759 765
760c) at least one request will be handled. 766=item c) at least one request will be handled.
767
768=back
761 769
762=item eio_set_max_poll_reqs (unsigned int nreqs) 770=item eio_set_max_poll_reqs (unsigned int nreqs)
763 771
764When C<nreqs> is non-zero, then C<eio_poll> will not handle more than 772When C<nreqs> is non-zero, then C<eio_poll> will not handle more than
765C<nreqs> requests per invocation. This is a less costly way to limit the 773C<nreqs> requests per invocation. This is a less costly way to limit the

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines