… | |
… | |
439 | of course I<doesn't>, and epoll just loves to report events for totally |
439 | of course I<doesn't>, and epoll just loves to report events for totally |
440 | I<different> file descriptors (even already closed ones, so one cannot |
440 | I<different> file descriptors (even already closed ones, so one cannot |
441 | even remove them from the set) than registered in the set (especially |
441 | even remove them from the set) than registered in the set (especially |
442 | on SMP systems). Libev tries to counter these spurious notifications by |
442 | on SMP systems). Libev tries to counter these spurious notifications by |
443 | employing an additional generation counter and comparing that against the |
443 | employing an additional generation counter and comparing that against the |
444 | events to filter out spurious ones, recreating the set when required. |
444 | events to filter out spurious ones, recreating the set when required. Last |
|
|
445 | not least, it also refuses to work with some file descriptors which work |
|
|
446 | perfectly fine with C<select> (files, many character devices...). |
445 | |
447 | |
446 | While stopping, setting and starting an I/O watcher in the same iteration |
448 | While stopping, setting and starting an I/O watcher in the same iteration |
447 | will result in some caching, there is still a system call per such |
449 | will result in some caching, there is still a system call per such |
448 | incident (because the same I<file descriptor> could point to a different |
450 | incident (because the same I<file descriptor> could point to a different |
449 | I<file description> now), so its best to avoid that. Also, C<dup ()>'ed |
451 | I<file description> now), so its best to avoid that. Also, C<dup ()>'ed |
… | |
… | |
3389 | Associates a different C<struct ev_loop> with this watcher. You can only |
3391 | Associates a different C<struct ev_loop> with this watcher. You can only |
3390 | do this when the watcher is inactive (and not pending either). |
3392 | do this when the watcher is inactive (and not pending either). |
3391 | |
3393 | |
3392 | =item w->set ([arguments]) |
3394 | =item w->set ([arguments]) |
3393 | |
3395 | |
3394 | Basically the same as C<ev_TYPE_set>, with the same arguments. Must be |
3396 | Basically the same as C<ev_TYPE_set>, with the same arguments. Either this |
3395 | called at least once. Unlike the C counterpart, an active watcher gets |
3397 | method or a suitable start method must be called at least once. Unlike the |
3396 | automatically stopped and restarted when reconfiguring it with this |
3398 | C counterpart, an active watcher gets automatically stopped and restarted |
3397 | method. |
3399 | when reconfiguring it with this method. |
3398 | |
3400 | |
3399 | =item w->start () |
3401 | =item w->start () |
3400 | |
3402 | |
3401 | Starts the watcher. Note that there is no C<loop> argument, as the |
3403 | Starts the watcher. Note that there is no C<loop> argument, as the |
3402 | constructor already stores the event loop. |
3404 | constructor already stores the event loop. |
3403 | |
3405 | |
|
|
3406 | =item w->start ([arguments]) |
|
|
3407 | |
|
|
3408 | Instead of calling C<set> and C<start> methods separately, it is often |
|
|
3409 | convenient to wrap them in one call. Uses the same type of arguments as |
|
|
3410 | the configure C<set> method of the watcher. |
|
|
3411 | |
3404 | =item w->stop () |
3412 | =item w->stop () |
3405 | |
3413 | |
3406 | Stops the watcher if it is active. Again, no C<loop> argument. |
3414 | Stops the watcher if it is active. Again, no C<loop> argument. |
3407 | |
3415 | |
3408 | =item w->again () (C<ev::timer>, C<ev::periodic> only) |
3416 | =item w->again () (C<ev::timer>, C<ev::periodic> only) |
… | |
… | |
3420 | |
3428 | |
3421 | =back |
3429 | =back |
3422 | |
3430 | |
3423 | =back |
3431 | =back |
3424 | |
3432 | |
3425 | Example: Define a class with an IO and idle watcher, start one of them in |
3433 | Example: Define a class with two I/O and idle watchers, start the I/O |
3426 | the constructor. |
3434 | watchers in the constructor. |
3427 | |
3435 | |
3428 | class myclass |
3436 | class myclass |
3429 | { |
3437 | { |
3430 | ev::io io ; void io_cb (ev::io &w, int revents); |
3438 | ev::io io ; void io_cb (ev::io &w, int revents); |
|
|
3439 | ev::io2 io2 ; void io2_cb (ev::io &w, int revents); |
3431 | ev::idle idle; void idle_cb (ev::idle &w, int revents); |
3440 | ev::idle idle; void idle_cb (ev::idle &w, int revents); |
3432 | |
3441 | |
3433 | myclass (int fd) |
3442 | myclass (int fd) |
3434 | { |
3443 | { |
3435 | io .set <myclass, &myclass::io_cb > (this); |
3444 | io .set <myclass, &myclass::io_cb > (this); |
|
|
3445 | io2 .set <myclass, &myclass::io2_cb > (this); |
3436 | idle.set <myclass, &myclass::idle_cb> (this); |
3446 | idle.set <myclass, &myclass::idle_cb> (this); |
3437 | |
3447 | |
3438 | io.start (fd, ev::READ); |
3448 | io.set (fd, ev::WRITE); // configure the watcher |
|
|
3449 | io.start (); // start it whenever convenient |
|
|
3450 | |
|
|
3451 | io2.start (fd, ev::READ); // set + start in one call |
3439 | } |
3452 | } |
3440 | }; |
3453 | }; |
3441 | |
3454 | |
3442 | |
3455 | |
3443 | =head1 OTHER LANGUAGE BINDINGS |
3456 | =head1 OTHER LANGUAGE BINDINGS |
… | |
… | |
4624 | watchers. |
4637 | watchers. |
4625 | |
4638 | |
4626 | =item C<double> must hold a time value in seconds with enough accuracy |
4639 | =item C<double> must hold a time value in seconds with enough accuracy |
4627 | |
4640 | |
4628 | The type C<double> is used to represent timestamps. It is required to |
4641 | The type C<double> is used to represent timestamps. It is required to |
4629 | have at least 51 bits of mantissa (and 9 bits of exponent), which is good |
4642 | have at least 51 bits of mantissa (and 9 bits of exponent), which is |
4630 | enough for at least into the year 4000. This requirement is fulfilled by |
4643 | good enough for at least into the year 4000 with millisecond accuracy |
|
|
4644 | (the design goal for libev). This requirement is overfulfilled by |
4631 | implementations implementing IEEE 754, which is basically all existing |
4645 | implementations using IEEE 754, which is basically all existing ones. With |
4632 | ones. With IEEE 754 doubles, you get microsecond accuracy until at least |
4646 | IEEE 754 doubles, you get microsecond accuracy until at least 2200. |
4633 | 2200. |
|
|
4634 | |
4647 | |
4635 | =back |
4648 | =back |
4636 | |
4649 | |
4637 | If you know of other additional requirements drop me a note. |
4650 | If you know of other additional requirements drop me a note. |
4638 | |
4651 | |