… | |
… | |
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 |
… | |
… | |
4423 | =head3 C<kqueue> is buggy |
4436 | =head3 C<kqueue> is buggy |
4424 | |
4437 | |
4425 | The kqueue syscall is broken in all known versions - most versions support |
4438 | The kqueue syscall is broken in all known versions - most versions support |
4426 | only sockets, many support pipes. |
4439 | only sockets, many support pipes. |
4427 | |
4440 | |
|
|
4441 | Libev tries to work around this by not using C<kqueue> by default on |
|
|
4442 | this rotten platform, but of course you can still ask for it when creating |
|
|
4443 | a loop. |
|
|
4444 | |
4428 | =head3 C<poll> is buggy |
4445 | =head3 C<poll> is buggy |
4429 | |
4446 | |
4430 | Instead of fixing C<kqueue>, Apple replaced their (working) C<poll> |
4447 | Instead of fixing C<kqueue>, Apple replaced their (working) C<poll> |
4431 | implementation by something calling C<kqueue> internally around the 10.5.6 |
4448 | implementation by something calling C<kqueue> internally around the 10.5.6 |
4432 | release, so now C<kqueue> I<and> C<poll> are broken. |
4449 | release, so now C<kqueue> I<and> C<poll> are broken. |
4433 | |
4450 | |
4434 | Libev tries to work around this by neither using C<kqueue> nor C<poll> by |
4451 | Libev tries to work around this by not using C<poll> by default on |
4435 | default on this rotten platform, but of course you cna still ask for them |
4452 | this rotten platform, but of course you can still ask for it when creating |
4436 | when creating a loop. |
4453 | a loop. |
4437 | |
4454 | |
4438 | =head3 C<select> is buggy |
4455 | =head3 C<select> is buggy |
4439 | |
4456 | |
4440 | All that's left is C<select>, and of course Apple found a way to fuck this |
4457 | All that's left is C<select>, and of course Apple found a way to fuck this |
4441 | one up as well: On OS/X, C<select> actively limits the number of file |
4458 | one up as well: On OS/X, C<select> actively limits the number of file |
4442 | descriptors you can pass in to 1024 - your program suddenyl crashes when |
4459 | descriptors you can pass in to 1024 - your program suddenly crashes when |
4443 | you use more. |
4460 | you use more. |
4444 | |
4461 | |
4445 | There is an undocumented "workaround" for this - defining |
4462 | There is an undocumented "workaround" for this - defining |
4446 | C<_DARWIN_UNLIMITED_SELECT>, which libev tries to use, so select I<should> |
4463 | C<_DARWIN_UNLIMITED_SELECT>, which libev tries to use, so select I<should> |
4447 | work on OS/X. |
4464 | work on OS/X. |
… | |
… | |
4464 | this mechanism is very buggy. If you run into high CPU usage, your program |
4481 | this mechanism is very buggy. If you run into high CPU usage, your program |
4465 | freezes or you get a large number of spurious wakeups, make sure you have |
4482 | freezes or you get a large number of spurious wakeups, make sure you have |
4466 | all the relevant and latest kernel patches applied. No, I don't know which |
4483 | all the relevant and latest kernel patches applied. No, I don't know which |
4467 | ones, but there are multiple ones. |
4484 | ones, but there are multiple ones. |
4468 | |
4485 | |
4469 | If you can't get it to work, you can try running the program with |
4486 | If you can't get it to work, you can try running the program by setting |
4470 | C<LIBEV_FLAGS=3> to only allow C<poll> and C<select> backends. |
4487 | the environment variable C<LIBEV_FLAGS=3> to only allow C<poll> and |
|
|
4488 | C<select> backends. |
4471 | |
4489 | |
4472 | =head2 AIX POLL BUG |
4490 | =head2 AIX POLL BUG |
4473 | |
4491 | |
4474 | AIX unfortunately has a broken C<poll.h> header. Libev works around |
4492 | AIX unfortunately has a broken C<poll.h> header. Libev works around |
4475 | this by trying to avoid the poll backend altogether (i.e. it's not even |
4493 | this by trying to avoid the poll backend altogether (i.e. it's not even |