… | |
… | |
736 | =item bool ev_is_pending (ev_TYPE *watcher) |
736 | =item bool ev_is_pending (ev_TYPE *watcher) |
737 | |
737 | |
738 | Returns a true value iff the watcher is pending, (i.e. it has outstanding |
738 | Returns a true value iff the watcher is pending, (i.e. it has outstanding |
739 | events but its callback has not yet been invoked). As long as a watcher |
739 | events but its callback has not yet been invoked). As long as a watcher |
740 | is pending (but not active) you must not call an init function on it (but |
740 | is pending (but not active) you must not call an init function on it (but |
741 | C<ev_TYPE_set> is safe) and you must make sure the watcher is available to |
741 | C<ev_TYPE_set> is safe), you must not change its priority, and you must |
742 | libev (e.g. you cnanot C<free ()> it). |
742 | make sure the watcher is available to libev (e.g. you cannot C<free ()> |
|
|
743 | it). |
743 | |
744 | |
744 | =item callback ev_cb (ev_TYPE *watcher) |
745 | =item callback ev_cb (ev_TYPE *watcher) |
745 | |
746 | |
746 | Returns the callback currently set on the watcher. |
747 | Returns the callback currently set on the watcher. |
747 | |
748 | |
… | |
… | |
766 | watchers on the same event and make sure one is called first. |
767 | watchers on the same event and make sure one is called first. |
767 | |
768 | |
768 | If you need to suppress invocation when higher priority events are pending |
769 | If you need to suppress invocation when higher priority events are pending |
769 | you need to look at C<ev_idle> watchers, which provide this functionality. |
770 | you need to look at C<ev_idle> watchers, which provide this functionality. |
770 | |
771 | |
|
|
772 | You I<must not> change the priority of a watcher as long as it is active or |
|
|
773 | pending. |
|
|
774 | |
771 | The default priority used by watchers when no priority has been set is |
775 | The default priority used by watchers when no priority has been set is |
772 | always C<0>, which is supposed to not be too high and not be too low :). |
776 | always C<0>, which is supposed to not be too high and not be too low :). |
773 | |
777 | |
774 | Setting a priority outside the range of C<EV_MINPRI> to C<EV_MAXPRI> is |
778 | Setting a priority outside the range of C<EV_MINPRI> to C<EV_MAXPRI> is |
775 | fine, as long as you do not mind that the priority value you query might |
779 | fine, as long as you do not mind that the priority value you query might |
776 | or might not have been adjusted to be within valid range. |
780 | or might not have been adjusted to be within valid range. |
|
|
781 | |
|
|
782 | =item ev_invoke (loop, ev_TYPE *watcher, int revents) |
|
|
783 | |
|
|
784 | Invoke the C<watcher> with the given C<loop> and C<revents>. Neither |
|
|
785 | C<loop> nor C<revents> need to be valid as long as the watcher callback |
|
|
786 | can deal with that fact. |
|
|
787 | |
|
|
788 | =item int ev_clear_pending (loop, ev_TYPE *watcher) |
|
|
789 | |
|
|
790 | If the watcher is pending, this function returns clears its pending status |
|
|
791 | and returns its C<revents> bitset (as if its callback was invoked). If the |
|
|
792 | watcher isn't pending it does nothing and returns C<0>. |
777 | |
793 | |
778 | =back |
794 | =back |
779 | |
795 | |
780 | |
796 | |
781 | =head2 ASSOCIATING CUSTOM DATA WITH A WATCHER |
797 | =head2 ASSOCIATING CUSTOM DATA WITH A WATCHER |
… | |
… | |
1749 | This automatically includes F<ev.h> and puts all of its definitions (many |
1765 | This automatically includes F<ev.h> and puts all of its definitions (many |
1750 | of them macros) into the global namespace. All C++ specific things are |
1766 | of them macros) into the global namespace. All C++ specific things are |
1751 | put into the C<ev> namespace. It should support all the same embedding |
1767 | put into the C<ev> namespace. It should support all the same embedding |
1752 | options as F<ev.h>, most notably C<EV_MULTIPLICITY>. |
1768 | options as F<ev.h>, most notably C<EV_MULTIPLICITY>. |
1753 | |
1769 | |
1754 | Care has been taken to keep the overhead low. The only data member added |
1770 | Care has been taken to keep the overhead low. The only data member the C++ |
1755 | to the C-style watchers is the event loop the watcher is associated with |
1771 | classes add (compared to plain C-style watchers) is the event loop pointer |
1756 | (or no additional members at all if you disable C<EV_MULTIPLICITY> when |
1772 | that the watcher is associated with (or no additional members at all if |
1757 | embedding libev). |
1773 | you disable C<EV_MULTIPLICITY> when embedding libev). |
1758 | |
1774 | |
1759 | Currently, functions and static and non-static member functions can be |
1775 | Currently, functions, and static and non-static member functions can be |
1760 | used as callbacks. Other types should be easy to add as long as they only |
1776 | used as callbacks. Other types should be easy to add as long as they only |
1761 | need one additional pointer for context. If you need support for other |
1777 | need one additional pointer for context. If you need support for other |
1762 | types of functors please contact the author (preferably after implementing |
1778 | types of functors please contact the author (preferably after implementing |
1763 | it). |
1779 | it). |
1764 | |
1780 | |
… | |
… | |
1828 | |
1844 | |
1829 | myclass obj; |
1845 | myclass obj; |
1830 | ev::io iow; |
1846 | ev::io iow; |
1831 | iow.set <myclass, &myclass::io_cb> (&obj); |
1847 | iow.set <myclass, &myclass::io_cb> (&obj); |
1832 | |
1848 | |
1833 | =item w->set (void (*function)(watcher &w, int), void *data = 0) |
1849 | =item w->set<function> (void *data = 0) |
1834 | |
1850 | |
1835 | Also sets a callback, but uses a static method or plain function as |
1851 | Also sets a callback, but uses a static method or plain function as |
1836 | callback. The optional C<data> argument will be stored in the watcher's |
1852 | callback. The optional C<data> argument will be stored in the watcher's |
1837 | C<data> member and is free for you to use. |
1853 | C<data> member and is free for you to use. |
1838 | |
1854 | |
|
|
1855 | The prototype of the C<function> must be C<void (*)(ev::TYPE &w, int)>. |
|
|
1856 | |
1839 | See the method-C<set> above for more details. |
1857 | See the method-C<set> above for more details. |
|
|
1858 | |
|
|
1859 | Example: |
|
|
1860 | |
|
|
1861 | static void io_cb (ev::io &w, int revents) { } |
|
|
1862 | iow.set <io_cb> (); |
1840 | |
1863 | |
1841 | =item w->set (struct ev_loop *) |
1864 | =item w->set (struct ev_loop *) |
1842 | |
1865 | |
1843 | Associates a different C<struct ev_loop> with this watcher. You can only |
1866 | Associates a different C<struct ev_loop> with this watcher. You can only |
1844 | do this when the watcher is inactive (and not pending either). |
1867 | do this when the watcher is inactive (and not pending either). |