… | |
… | |
323 | fatal ("no epoll found here, maybe it hides under your chair"); |
323 | fatal ("no epoll found here, maybe it hides under your chair"); |
324 | |
324 | |
325 | =item ev_default_destroy () |
325 | =item ev_default_destroy () |
326 | |
326 | |
327 | Destroys the default loop again (frees all memory and kernel state |
327 | Destroys the default loop again (frees all memory and kernel state |
328 | etc.). This stops all registered event watchers (by not touching them in |
328 | etc.). None of the active event watchers will be stopped in the normal |
329 | any way whatsoever, although you cannot rely on this :). |
329 | sense, so e.g. C<ev_is_active> might still return true. It is your |
|
|
330 | responsibility to either stop all watchers cleanly yoursef I<before> |
|
|
331 | calling this function, or cope with the fact afterwards (which is usually |
|
|
332 | the easiest thing, youc na just ignore the watchers and/or C<free ()> them |
|
|
333 | for example). |
330 | |
334 | |
331 | =item ev_loop_destroy (loop) |
335 | =item ev_loop_destroy (loop) |
332 | |
336 | |
333 | Like C<ev_default_destroy>, but destroys an event loop created by an |
337 | Like C<ev_default_destroy>, but destroys an event loop created by an |
334 | earlier call to C<ev_loop_new>. |
338 | earlier call to C<ev_loop_new>. |
… | |
… | |
852 | (and unfortunately a bit complex). |
856 | (and unfortunately a bit complex). |
853 | |
857 | |
854 | Unlike C<ev_timer>'s, they are not based on real time (or relative time) |
858 | Unlike C<ev_timer>'s, they are not based on real time (or relative time) |
855 | but on wallclock time (absolute time). You can tell a periodic watcher |
859 | but on wallclock time (absolute time). You can tell a periodic watcher |
856 | to trigger "at" some specific point in time. For example, if you tell a |
860 | to trigger "at" some specific point in time. For example, if you tell a |
857 | periodic watcher to trigger in 10 seconds (by specifiying e.g. c<ev_now () |
861 | periodic watcher to trigger in 10 seconds (by specifiying e.g. C<ev_now () |
858 | + 10.>) and then reset your system clock to the last year, then it will |
862 | + 10.>) and then reset your system clock to the last year, then it will |
859 | take a year to trigger the event (unlike an C<ev_timer>, which would trigger |
863 | take a year to trigger the event (unlike an C<ev_timer>, which would trigger |
860 | roughly 10 seconds later and of course not if you reset your system time |
864 | roughly 10 seconds later and of course not if you reset your system time |
861 | again). |
865 | again). |
862 | |
866 | |
… | |
… | |
1306 | |
1310 | |
1307 | =back |
1311 | =back |
1308 | |
1312 | |
1309 | =head1 C++ SUPPORT |
1313 | =head1 C++ SUPPORT |
1310 | |
1314 | |
1311 | TBD. |
1315 | Libev comes with some simplistic wrapper classes for C++ that mainly allow |
|
|
1316 | you to use some convinience methods to start/stop watchers and also change |
|
|
1317 | the callback model to a model using method callbacks on objects. |
|
|
1318 | |
|
|
1319 | To use it, |
|
|
1320 | |
|
|
1321 | #include <ev++.h> |
|
|
1322 | |
|
|
1323 | (it is not installed by default). This automatically includes F<ev.h> |
|
|
1324 | and puts all of its definitions (many of them macros) into the global |
|
|
1325 | namespace. All C++ specific things are put into the C<ev> namespace. |
|
|
1326 | |
|
|
1327 | It should support all the same embedding options as F<ev.h>, most notably |
|
|
1328 | C<EV_MULTIPLICITY>. |
|
|
1329 | |
|
|
1330 | Here is a list of things available in the C<ev> namespace: |
|
|
1331 | |
|
|
1332 | =over 4 |
|
|
1333 | |
|
|
1334 | =item C<ev::READ>, C<ev::WRITE> etc. |
|
|
1335 | |
|
|
1336 | These are just enum values with the same values as the C<EV_READ> etc. |
|
|
1337 | macros from F<ev.h>. |
|
|
1338 | |
|
|
1339 | =item C<ev::tstamp>, C<ev::now> |
|
|
1340 | |
|
|
1341 | Aliases to the same types/functions as with the C<ev_> prefix. |
|
|
1342 | |
|
|
1343 | =item C<ev::io>, C<ev::timer>, C<ev::periodic>, C<ev::idle>, C<ev::sig> etc. |
|
|
1344 | |
|
|
1345 | For each C<ev_TYPE> watcher in F<ev.h> there is a corresponding class of |
|
|
1346 | the same name in the C<ev> namespace, with the exception of C<ev_signal> |
|
|
1347 | which is called C<ev::sig> to avoid clashes with the C<signal> macro |
|
|
1348 | defines by many implementations. |
|
|
1349 | |
|
|
1350 | All of those classes have these methods: |
|
|
1351 | |
|
|
1352 | =over 4 |
|
|
1353 | |
|
|
1354 | =item ev::TYPE::TYPE (object *, object::method *) |
|
|
1355 | |
|
|
1356 | =item ev::TYPE::TYPE (object *, object::method *, struct ev_loop *) |
|
|
1357 | |
|
|
1358 | =item ev::TYPE::~TYPE |
|
|
1359 | |
|
|
1360 | The constructor takes a pointer to an object and a method pointer to |
|
|
1361 | the event handler callback to call in this class. The constructor calls |
|
|
1362 | C<ev_init> for you, which means you have to call the C<set> method |
|
|
1363 | before starting it. If you do not specify a loop then the constructor |
|
|
1364 | automatically associates the default loop with this watcher. |
|
|
1365 | |
|
|
1366 | The destructor automatically stops the watcher if it is active. |
|
|
1367 | |
|
|
1368 | =item w->set (struct ev_loop *) |
|
|
1369 | |
|
|
1370 | Associates a different C<struct ev_loop> with this watcher. You can only |
|
|
1371 | do this when the watcher is inactive (and not pending either). |
|
|
1372 | |
|
|
1373 | =item w->set ([args]) |
|
|
1374 | |
|
|
1375 | Basically the same as C<ev_TYPE_set>, with the same args. Must be |
|
|
1376 | called at least once. Unlike the C counterpart, an active watcher gets |
|
|
1377 | automatically stopped and restarted. |
|
|
1378 | |
|
|
1379 | =item w->start () |
|
|
1380 | |
|
|
1381 | Starts the watcher. Note that there is no C<loop> argument as the |
|
|
1382 | constructor already takes the loop. |
|
|
1383 | |
|
|
1384 | =item w->stop () |
|
|
1385 | |
|
|
1386 | Stops the watcher if it is active. Again, no C<loop> argument. |
|
|
1387 | |
|
|
1388 | =item w->again () C<ev::timer>, C<ev::periodic> only |
|
|
1389 | |
|
|
1390 | For C<ev::timer> and C<ev::periodic>, this invokes the corresponding |
|
|
1391 | C<ev_TYPE_again> function. |
|
|
1392 | |
|
|
1393 | =item w->sweep () C<ev::embed> only |
|
|
1394 | |
|
|
1395 | Invokes C<ev_embed_sweep>. |
|
|
1396 | |
|
|
1397 | =back |
|
|
1398 | |
|
|
1399 | =back |
|
|
1400 | |
|
|
1401 | Example: Define a class with an IO and idle watcher, start one of them in |
|
|
1402 | the constructor. |
|
|
1403 | |
|
|
1404 | class myclass |
|
|
1405 | { |
|
|
1406 | ev_io io; void io_cb (ev::io &w, int revents); |
|
|
1407 | ev_idle idle void idle_cb (ev::idle &w, int revents); |
|
|
1408 | |
|
|
1409 | myclass (); |
|
|
1410 | } |
|
|
1411 | |
|
|
1412 | myclass::myclass (int fd) |
|
|
1413 | : io (this, &myclass::io_cb), |
|
|
1414 | idle (this, &myclass::idle_cb) |
|
|
1415 | { |
|
|
1416 | io.start (fd, ev::READ); |
|
|
1417 | } |
1312 | |
1418 | |
1313 | =head1 AUTHOR |
1419 | =head1 AUTHOR |
1314 | |
1420 | |
1315 | Marc Lehmann <libev@schmorp.de>. |
1421 | Marc Lehmann <libev@schmorp.de>. |
1316 | |
1422 | |