… | |
… | |
404 | =head1 WATCHER TYPES |
404 | =head1 WATCHER TYPES |
405 | |
405 | |
406 | This section describes each watcher in detail, but will not repeat |
406 | This section describes each watcher in detail, but will not repeat |
407 | information given in the last section. |
407 | information given in the last section. |
408 | |
408 | |
409 | =head2 C<ev_io> - is my file descriptor readable or writable |
409 | =head2 C<ev_io> - is this file descriptor readable or writable |
410 | |
410 | |
411 | I/O watchers check whether a file descriptor is readable or writable |
411 | I/O watchers check whether a file descriptor is readable or writable |
412 | in each iteration of the event loop (This behaviour is called |
412 | in each iteration of the event loop (This behaviour is called |
413 | level-triggering because you keep receiving events as long as the |
413 | level-triggering because you keep receiving events as long as the |
414 | condition persists. Remember you cna stop the watcher if you don't want to |
414 | condition persists. Remember you cna stop the watcher if you don't want to |
… | |
… | |
544 | |
544 | |
545 | ev_periodic_set (&periodic, 0., 3600., 0); |
545 | ev_periodic_set (&periodic, 0., 3600., 0); |
546 | |
546 | |
547 | This doesn't mean there will always be 3600 seconds in between triggers, |
547 | This doesn't mean there will always be 3600 seconds in between triggers, |
548 | but only that the the callback will be called when the system time shows a |
548 | but only that the the callback will be called when the system time shows a |
549 | full hour (UTC), or more correct, when the system time is evenly divisible |
549 | full hour (UTC), or more correctly, when the system time is evenly divisible |
550 | by 3600. |
550 | by 3600. |
551 | |
551 | |
552 | Another way to think about it (for the mathematically inclined) is that |
552 | Another way to think about it (for the mathematically inclined) is that |
553 | C<ev_periodic> will try to run the callback in this mode at the next possible |
553 | C<ev_periodic> will try to run the callback in this mode at the next possible |
554 | time where C<time = at (mod interval)>, regardless of any time jumps. |
554 | time where C<time = at (mod interval)>, regardless of any time jumps. |
… | |
… | |
559 | ignored. Instead, each time the periodic watcher gets scheduled, the |
559 | ignored. Instead, each time the periodic watcher gets scheduled, the |
560 | reschedule callback will be called with the watcher as first, and the |
560 | reschedule callback will be called with the watcher as first, and the |
561 | current time as second argument. |
561 | current time as second argument. |
562 | |
562 | |
563 | NOTE: I<This callback MUST NOT stop or destroy the periodic or any other |
563 | NOTE: I<This callback MUST NOT stop or destroy the periodic or any other |
564 | periodic watcher, ever, or make any event loop modificstions>. If you need |
564 | periodic watcher, ever, or make any event loop modifications>. If you need |
565 | to stop it, return 1e30 (or so, fudge fudge) and stop it afterwards. |
565 | to stop it, return C<now + 1e30> (or so, fudge fudge) and stop it afterwards. |
566 | |
566 | |
|
|
567 | Also, I<< this callback must always return a time that is later than the |
|
|
568 | passed C<now> value >>. Not even C<now> itself will be ok. |
|
|
569 | |
567 | Its prototype is c<ev_tstamp (*reschedule_cb)(struct ev_periodic *w, |
570 | Its prototype is C<ev_tstamp (*reschedule_cb)(struct ev_periodic *w, |
568 | ev_tstamp now)>, e.g.: |
571 | ev_tstamp now)>, e.g.: |
569 | |
572 | |
570 | static ev_tstamp my_rescheduler (struct ev_periodic *w, ev_tstamp now) |
573 | static ev_tstamp my_rescheduler (struct ev_periodic *w, ev_tstamp now) |
571 | { |
574 | { |
572 | return now + 60.; |
575 | return now + 60.; |