… | |
… | |
115 | |
115 | |
116 | Returns the current time as libev would use it. Please note that the |
116 | Returns the current time as libev would use it. Please note that the |
117 | C<ev_now> function is usually faster and also often returns the timestamp |
117 | C<ev_now> function is usually faster and also often returns the timestamp |
118 | you actually want to know. |
118 | you actually want to know. |
119 | |
119 | |
|
|
120 | =item ev_sleep (ev_tstamp interval) |
|
|
121 | |
|
|
122 | Sleep for the given interval: The current thread will be blocked until |
|
|
123 | either it is interrupted or the given time interval has passed. Basically |
|
|
124 | this is a subsecond-resolution C<sleep ()>. |
|
|
125 | |
120 | =item int ev_version_major () |
126 | =item int ev_version_major () |
121 | |
127 | |
122 | =item int ev_version_minor () |
128 | =item int ev_version_minor () |
123 | |
129 | |
124 | You can find out the major and minor ABI version numbers of the library |
130 | You can find out the major and minor ABI version numbers of the library |
… | |
… | |
317 | For few fds, this backend is a bit little slower than poll and select, |
323 | For few fds, this backend is a bit little slower than poll and select, |
318 | but it scales phenomenally better. While poll and select usually scale |
324 | but it scales phenomenally better. While poll and select usually scale |
319 | like O(total_fds) where n is the total number of fds (or the highest fd), |
325 | like O(total_fds) where n is the total number of fds (or the highest fd), |
320 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
326 | epoll scales either O(1) or O(active_fds). The epoll design has a number |
321 | of shortcomings, such as silently dropping events in some hard-to-detect |
327 | of shortcomings, such as silently dropping events in some hard-to-detect |
322 | cases and rewuiring a syscall per fd change, no fork support and bad |
328 | cases and rewiring a syscall per fd change, no fork support and bad |
323 | support for dup: |
329 | support for dup: |
324 | |
330 | |
325 | While stopping, setting and starting an I/O watcher in the same iteration |
331 | While stopping, setting and starting an I/O watcher in the same iteration |
326 | will result in some caching, there is still a syscall per such incident |
332 | will result in some caching, there is still a syscall per such incident |
327 | (because the fd could point to a different file description now), so its |
333 | (because the fd could point to a different file description now), so its |
… | |
… | |
569 | Example: For some weird reason, unregister the above signal handler again. |
575 | Example: For some weird reason, unregister the above signal handler again. |
570 | |
576 | |
571 | ev_ref (loop); |
577 | ev_ref (loop); |
572 | ev_signal_stop (loop, &exitsig); |
578 | ev_signal_stop (loop, &exitsig); |
573 | |
579 | |
|
|
580 | =item ev_set_io_collect_interval (loop, ev_tstamp interval) |
|
|
581 | |
|
|
582 | =item ev_set_timeout_collect_interval (loop, ev_tstamp interval) |
|
|
583 | |
|
|
584 | These advanced functions influence the time that libev will spend waiting |
|
|
585 | for events. Both are by default C<0>, meaning that libev will try to |
|
|
586 | invoke timer/periodic callbacks and I/O callbacks with minimum latency. |
|
|
587 | |
|
|
588 | Setting these to a higher value (the C<interval> I<must> be >= C<0>) |
|
|
589 | allows libev to delay invocation of I/O and timer/periodic callbacks to |
|
|
590 | increase efficiency of loop iterations. |
|
|
591 | |
|
|
592 | The background is that sometimes your program runs just fast enough to |
|
|
593 | handle one (or very few) event(s) per loop iteration. While this makes |
|
|
594 | the program responsive, it also wastes a lot of CPU time to poll for new |
|
|
595 | events, especially with backends like C<select ()> which have a high |
|
|
596 | overhead for the actual polling but can deliver many events at once. |
|
|
597 | |
|
|
598 | By setting a higher I<io collect interval> you allow libev to spend more |
|
|
599 | time collecting I/O events, so you can handle more events per iteration, |
|
|
600 | at the cost of increasing latency. Timeouts (both C<ev_periodic> and |
|
|
601 | C<ev_timer>) will be not affected. |
|
|
602 | |
|
|
603 | Likewise, by setting a higher I<timeout collect interval> you allow libev |
|
|
604 | to spend more time collecting timeouts, at the expense of increased |
|
|
605 | latency (the watcher callback will be called later). C<ev_io> watchers |
|
|
606 | will not be affected. |
|
|
607 | |
|
|
608 | Many programs can usually benefit by setting the io collect interval to |
|
|
609 | a value near C<0.1> or so, which is often enough for interactive servers |
|
|
610 | (of course not for games), likewise for timeouts. It usually doesn't make |
|
|
611 | much sense to set it to a lower value than C<0.01>, as this approsaches |
|
|
612 | the timing granularity of most systems. |
|
|
613 | |
574 | =back |
614 | =back |
575 | |
615 | |
576 | |
616 | |
577 | =head1 ANATOMY OF A WATCHER |
617 | =head1 ANATOMY OF A WATCHER |
578 | |
618 | |
… | |
… | |
2297 | runtime if successful). Otherwise no use of the realtime clock option will |
2337 | runtime if successful). Otherwise no use of the realtime clock option will |
2298 | be attempted. This effectively replaces C<gettimeofday> by C<clock_get |
2338 | be attempted. This effectively replaces C<gettimeofday> by C<clock_get |
2299 | (CLOCK_REALTIME, ...)> and will not normally affect correctness. See the |
2339 | (CLOCK_REALTIME, ...)> and will not normally affect correctness. See the |
2300 | note about libraries in the description of C<EV_USE_MONOTONIC>, though. |
2340 | note about libraries in the description of C<EV_USE_MONOTONIC>, though. |
2301 | |
2341 | |
|
|
2342 | =item EV_USE_NANOSLEEP |
|
|
2343 | |
|
|
2344 | If defined to be C<1>, libev will assume that C<nanosleep ()> is available |
|
|
2345 | and will use it for delays. Otherwise it will use C<select ()>. |
|
|
2346 | |
2302 | =item EV_USE_SELECT |
2347 | =item EV_USE_SELECT |
2303 | |
2348 | |
2304 | If undefined or defined to be C<1>, libev will compile in support for the |
2349 | If undefined or defined to be C<1>, libev will compile in support for the |
2305 | C<select>(2) backend. No attempt at autodetection will be done: if no |
2350 | C<select>(2) backend. No attempt at autodetection will be done: if no |
2306 | other method takes over, select will be it. Otherwise the select backend |
2351 | other method takes over, select will be it. Otherwise the select backend |