… | |
… | |
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="Sun Dec 9 20:47:27 2007" /> |
9 | <meta name="created" content="Wed Dec 12 05:53:55 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 --> |
… | |
… | |
27 | <ul><li><a href="#GENERIC_WATCHER_FUNCTIONS">GENERIC WATCHER FUNCTIONS</a></li> |
27 | <ul><li><a href="#GENERIC_WATCHER_FUNCTIONS">GENERIC WATCHER FUNCTIONS</a></li> |
28 | <li><a href="#ASSOCIATING_CUSTOM_DATA_WITH_A_WATCH">ASSOCIATING CUSTOM DATA WITH A WATCHER</a></li> |
28 | <li><a href="#ASSOCIATING_CUSTOM_DATA_WITH_A_WATCH">ASSOCIATING CUSTOM DATA WITH A WATCHER</a></li> |
29 | </ul> |
29 | </ul> |
30 | </li> |
30 | </li> |
31 | <li><a href="#WATCHER_TYPES">WATCHER TYPES</a> |
31 | <li><a href="#WATCHER_TYPES">WATCHER TYPES</a> |
32 | <ul><li><a href="#code_ev_io_code_is_this_file_descrip"><code>ev_io</code> - is this file descriptor readable or writable?</a></li> |
32 | <ul><li><a href="#code_ev_io_code_is_this_file_descrip"><code>ev_io</code> - is this file descriptor readable or writable?</a> |
|
|
33 | <ul><li><a href="#The_special_problem_of_disappearing_">The special problem of disappearing file descriptors</a></li> |
|
|
34 | </ul> |
|
|
35 | </li> |
33 | <li><a href="#code_ev_timer_code_relative_and_opti"><code>ev_timer</code> - relative and optionally repeating timeouts</a></li> |
36 | <li><a href="#code_ev_timer_code_relative_and_opti"><code>ev_timer</code> - relative and optionally repeating timeouts</a></li> |
34 | <li><a href="#code_ev_periodic_code_to_cron_or_not"><code>ev_periodic</code> - to cron or not to cron?</a></li> |
37 | <li><a href="#code_ev_periodic_code_to_cron_or_not"><code>ev_periodic</code> - to cron or not to cron?</a></li> |
35 | <li><a href="#code_ev_signal_code_signal_me_when_a"><code>ev_signal</code> - signal me when a signal gets signalled!</a></li> |
38 | <li><a href="#code_ev_signal_code_signal_me_when_a"><code>ev_signal</code> - signal me when a signal gets signalled!</a></li> |
36 | <li><a href="#code_ev_child_code_watch_out_for_pro"><code>ev_child</code> - watch out for process status changes</a></li> |
39 | <li><a href="#code_ev_child_code_watch_out_for_pro"><code>ev_child</code> - watch out for process status changes</a></li> |
37 | <li><a href="#code_ev_stat_code_did_the_file_attri"><code>ev_stat</code> - did the file attributes just change?</a></li> |
40 | <li><a href="#code_ev_stat_code_did_the_file_attri"><code>ev_stat</code> - did the file attributes just change?</a></li> |
… | |
… | |
941 | <p>If you cannot run the fd in non-blocking mode (for example you should not |
944 | <p>If you cannot run the fd in non-blocking mode (for example you should not |
942 | play around with an Xlib connection), then you have to seperately re-test |
945 | play around with an Xlib connection), then you have to seperately re-test |
943 | whether a file descriptor is really ready with a known-to-be good interface |
946 | whether a file descriptor is really ready with a known-to-be good interface |
944 | such as poll (fortunately in our Xlib example, Xlib already does this on |
947 | such as poll (fortunately in our Xlib example, Xlib already does this on |
945 | its own, so its quite safe to use).</p> |
948 | its own, so its quite safe to use).</p> |
|
|
949 | |
|
|
950 | </div> |
|
|
951 | <h3 id="The_special_problem_of_disappearing_">The special problem of disappearing file descriptors</h3> |
|
|
952 | <div id="The_special_problem_of_disappearing_-2"> |
|
|
953 | <p>Some backends (e.g kqueue, epoll) need to be told about closing a file |
|
|
954 | descriptor (either by calling <code>close</code> explicitly or by any other means, |
|
|
955 | such as <code>dup</code>). The reason is that you register interest in some file |
|
|
956 | descriptor, but when it goes away, the operating system will silently drop |
|
|
957 | this interest. If another file descriptor with the same number then is |
|
|
958 | registered with libev, there is no efficient way to see that this is, in |
|
|
959 | fact, a different file descriptor.</p> |
|
|
960 | <p>To avoid having to explicitly tell libev about such cases, libev follows |
|
|
961 | the following policy: Each time <code>ev_io_set</code> is being called, libev |
|
|
962 | will assume that this is potentially a new file descriptor, otherwise |
|
|
963 | it is assumed that the file descriptor stays the same. That means that |
|
|
964 | you <i>have</i> to call <code>ev_io_set</code> (or <code>ev_io_init</code>) when you change the |
|
|
965 | descriptor even if the file descriptor number itself did not change.</p> |
|
|
966 | <p>This is how one would do it normally anyway, the important point is that |
|
|
967 | the libev application should not optimise around libev but should leave |
|
|
968 | optimisations to libev.</p> |
|
|
969 | |
|
|
970 | |
|
|
971 | |
|
|
972 | |
946 | <dl> |
973 | <dl> |
947 | <dt>ev_io_init (ev_io *, callback, int fd, int events)</dt> |
974 | <dt>ev_io_init (ev_io *, callback, int fd, int events)</dt> |
948 | <dt>ev_io_set (ev_io *, int fd, int events)</dt> |
975 | <dt>ev_io_set (ev_io *, int fd, int events)</dt> |
949 | <dd> |
976 | <dd> |
950 | <p>Configures an <code>ev_io</code> watcher. The <code>fd</code> is the file descriptor to |
977 | <p>Configures an <code>ev_io</code> watcher. The <code>fd</code> is the file descriptor to |