… | |
… | |
4 | <head> |
4 | <head> |
5 | <title>libev</title> |
5 | <title>libev</title> |
6 | <meta name="description" content="Pod documentation for libev" /> |
6 | <meta name="description" content="Pod documentation for libev" /> |
7 | <meta name="inputfile" content="<standard input>" /> |
7 | <meta name="inputfile" content="<standard input>" /> |
8 | <meta name="outputfile" content="<standard output>" /> |
8 | <meta name="outputfile" content="<standard output>" /> |
9 | <meta name="created" content="Tue Nov 27 21:29:04 2007" /> |
9 | <meta name="created" content="Tue Nov 27 21:38:05 2007" /> |
10 | <meta name="generator" content="Pod::Xhtml 1.57" /> |
10 | <meta name="generator" content="Pod::Xhtml 1.57" /> |
11 | <link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head> |
11 | <link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head> |
12 | <body> |
12 | <body> |
13 | <div class="pod"> |
13 | <div class="pod"> |
14 | <!-- INDEX START --> |
14 | <!-- INDEX START --> |
… | |
… | |
741 | events but its callback has not yet been invoked). As long as a watcher |
741 | events but its callback has not yet been invoked). As long as a watcher |
742 | is pending (but not active) you must not call an init function on it (but |
742 | is pending (but not active) you must not call an init function on it (but |
743 | <code>ev_TYPE_set</code> is safe) and you must make sure the watcher is available to |
743 | <code>ev_TYPE_set</code> is safe) and you must make sure the watcher is available to |
744 | libev (e.g. you cnanot <code>free ()</code> it).</p> |
744 | libev (e.g. you cnanot <code>free ()</code> it).</p> |
745 | </dd> |
745 | </dd> |
746 | <dt>callback = ev_cb (ev_TYPE *watcher)</dt> |
746 | <dt>callback ev_cb (ev_TYPE *watcher)</dt> |
747 | <dd> |
747 | <dd> |
748 | <p>Returns the callback currently set on the watcher.</p> |
748 | <p>Returns the callback currently set on the watcher.</p> |
749 | </dd> |
749 | </dd> |
750 | <dt>ev_cb_set (ev_TYPE *watcher, callback)</dt> |
750 | <dt>ev_cb_set (ev_TYPE *watcher, callback)</dt> |
751 | <dd> |
751 | <dd> |
… | |
… | |
783 | struct my_io *w = (struct my_io *)w_; |
783 | struct my_io *w = (struct my_io *)w_; |
784 | ... |
784 | ... |
785 | } |
785 | } |
786 | |
786 | |
787 | </pre> |
787 | </pre> |
788 | <p>More interesting and less C-conformant ways of catsing your callback type |
788 | <p>More interesting and less C-conformant ways of casting your callback type |
789 | have been omitted....</p> |
789 | instead have been omitted.</p> |
|
|
790 | <p>Another common scenario is having some data structure with multiple |
|
|
791 | watchers:</p> |
|
|
792 | <pre> struct my_biggy |
|
|
793 | { |
|
|
794 | int some_data; |
|
|
795 | ev_timer t1; |
|
|
796 | ev_timer t2; |
|
|
797 | } |
790 | |
798 | |
|
|
799 | </pre> |
|
|
800 | <p>In this case getting the pointer to <code>my_biggy</code> is a bit more complicated, |
|
|
801 | you need to use <code>offsetof</code>:</p> |
|
|
802 | <pre> #include <stddef.h> |
791 | |
803 | |
|
|
804 | static void |
|
|
805 | t1_cb (EV_P_ struct ev_timer *w, int revents) |
|
|
806 | { |
|
|
807 | struct my_biggy big = (struct my_biggy * |
|
|
808 | (((char *)w) - offsetof (struct my_biggy, t1)); |
|
|
809 | } |
792 | |
810 | |
|
|
811 | static void |
|
|
812 | t2_cb (EV_P_ struct ev_timer *w, int revents) |
|
|
813 | { |
|
|
814 | struct my_biggy big = (struct my_biggy * |
|
|
815 | (((char *)w) - offsetof (struct my_biggy, t2)); |
|
|
816 | } |
793 | |
817 | |
|
|
818 | |
|
|
819 | |
|
|
820 | |
|
|
821 | </pre> |
794 | |
822 | |
795 | </div> |
823 | </div> |
796 | <h1 id="WATCHER_TYPES">WATCHER TYPES</h1> |
824 | <h1 id="WATCHER_TYPES">WATCHER TYPES</h1> |
797 | <div id="WATCHER_TYPES_CONTENT"> |
825 | <div id="WATCHER_TYPES_CONTENT"> |
798 | <p>This section describes each watcher in detail, but will not repeat |
826 | <p>This section describes each watcher in detail, but will not repeat |