… | |
… | |
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="Mon Nov 12 09:12:14 2007" /> |
9 | <meta name="created" content="Mon Nov 12 09:16:01 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 --> |
… | |
… | |
72 | <p>Libev supports select, poll, the linux-specific epoll and the bsd-specific |
72 | <p>Libev supports select, poll, the linux-specific epoll and the bsd-specific |
73 | kqueue mechanisms for file descriptor events, relative timers, absolute |
73 | kqueue mechanisms for file descriptor events, relative timers, absolute |
74 | timers with customised rescheduling, signal events, process status change |
74 | timers with customised rescheduling, signal events, process status change |
75 | events (related to SIGCHLD), and event watchers dealing with the event |
75 | events (related to SIGCHLD), and event watchers dealing with the event |
76 | loop mechanism itself (idle, prepare and check watchers). It also is quite |
76 | loop mechanism itself (idle, prepare and check watchers). It also is quite |
77 | fast (see a <a href="http://libev.schmorp.de/bench.html">benchmark</a> comparing it |
77 | fast (see this <a href="http://libev.schmorp.de/bench.html">benchmark</a> comparing |
78 | to libevent).</p> |
78 | it to libevent for example).</p> |
79 | |
79 | |
80 | </div> |
80 | </div> |
81 | <h1 id="CONVENTIONS">CONVENTIONS</h1><p><a href="#TOP" class="toplink">Top</a></p> |
81 | <h1 id="CONVENTIONS">CONVENTIONS</h1><p><a href="#TOP" class="toplink">Top</a></p> |
82 | <div id="CONVENTIONS_CONTENT"> |
82 | <div id="CONVENTIONS_CONTENT"> |
83 | <p>Libev is very configurable. In this manual the default configuration |
83 | <p>Libev is very configurable. In this manual the default configuration |
84 | will be described, which supports multiple event loops. For more info |
84 | will be described, which supports multiple event loops. For more info |
85 | about various configuraiton options please have a look at the file |
85 | about various configuration options please have a look at the file |
86 | <cite>README.embed</cite> in the libev distribution. If libev was configured without |
86 | <cite>README.embed</cite> in the libev distribution. If libev was configured without |
87 | support for multiple event loops, then all functions taking an initial |
87 | support for multiple event loops, then all functions taking an initial |
88 | argument of name <code>loop</code> (which is always of type <code>struct ev_loop *</code>) |
88 | argument of name <code>loop</code> (which is always of type <code>struct ev_loop *</code>) |
89 | will not have this argument.</p> |
89 | will not have this argument.</p> |
90 | |
90 | |
… | |
… | |
115 | not a problem.</p> |
115 | not a problem.</p> |
116 | </dd> |
116 | </dd> |
117 | <dt>ev_set_allocator (void *(*cb)(void *ptr, long size))</dt> |
117 | <dt>ev_set_allocator (void *(*cb)(void *ptr, long size))</dt> |
118 | <dd> |
118 | <dd> |
119 | <p>Sets the allocation function to use (the prototype is similar to the |
119 | <p>Sets the allocation function to use (the prototype is similar to the |
120 | realloc function). It is used to allocate and free memory (no surprises |
120 | realloc C function, the semantics are identical). It is used to allocate |
121 | here). If it returns zero when memory needs to be allocated, the library |
121 | and free memory (no surprises here). If it returns zero when memory |
122 | might abort or take some potentially destructive action. The default is |
122 | needs to be allocated, the library might abort or take some potentially |
123 | your system realloc function.</p> |
123 | destructive action. The default is your system realloc function.</p> |
124 | <p>You could override this function in high-availability programs to, say, |
124 | <p>You could override this function in high-availability programs to, say, |
125 | free some memory if it cannot allocate memory, to use a special allocator, |
125 | free some memory if it cannot allocate memory, to use a special allocator, |
126 | or even to sleep a while and retry until some memory is available.</p> |
126 | or even to sleep a while and retry until some memory is available.</p> |
127 | </dd> |
127 | </dd> |
128 | <dt>ev_set_syserr_cb (void (*cb)(const char *msg));</dt> |
128 | <dt>ev_set_syserr_cb (void (*cb)(const char *msg));</dt> |
129 | <dd> |
129 | <dd> |
130 | <p>Set the callback function to call on a retryable syscall error (such |
130 | <p>Set the callback function to call on a retryable syscall error (such |
131 | as failed select, poll, epoll_wait). The message is a printable string |
131 | as failed select, poll, epoll_wait). The message is a printable string |
132 | indicating the system call or subsystem causing the problem. If this |
132 | indicating the system call or subsystem causing the problem. If this |
133 | callback is set, then libev will expect it to remedy the sitution, no |
133 | callback is set, then libev will expect it to remedy the sitution, no |
134 | matter what, when it returns. That is, libev will geenrally retry the |
134 | matter what, when it returns. That is, libev will generally retry the |
135 | requested operation, or, if the condition doesn't go away, do bad stuff |
135 | requested operation, or, if the condition doesn't go away, do bad stuff |
136 | (such as abort).</p> |
136 | (such as abort).</p> |
137 | </dd> |
137 | </dd> |
138 | </dl> |
138 | </dl> |
139 | |
139 | |
… | |
… | |
143 | <p>An event loop is described by a <code>struct ev_loop *</code>. The library knows two |
143 | <p>An event loop is described by a <code>struct ev_loop *</code>. The library knows two |
144 | types of such loops, the <i>default</i> loop, which supports signals and child |
144 | types of such loops, the <i>default</i> loop, which supports signals and child |
145 | events, and dynamically created loops which do not.</p> |
145 | events, and dynamically created loops which do not.</p> |
146 | <p>If you use threads, a common model is to run the default event loop |
146 | <p>If you use threads, a common model is to run the default event loop |
147 | in your main thread (or in a separate thrad) and for each thread you |
147 | in your main thread (or in a separate thrad) and for each thread you |
148 | create, you also create another event loop. Libev itself does no lockign |
148 | create, you also create another event loop. Libev itself does no locking |
149 | whatsoever, so if you mix calls to different event loops, make sure you |
149 | whatsoever, so if you mix calls to the same event loop in different |
150 | lock (this is usually a bad idea, though, even if done right).</p> |
150 | threads, make sure you lock (this is usually a bad idea, though, even if |
|
|
151 | done correctly, because its hideous and inefficient).</p> |
151 | <dl> |
152 | <dl> |
152 | <dt>struct ev_loop *ev_default_loop (unsigned int flags)</dt> |
153 | <dt>struct ev_loop *ev_default_loop (unsigned int flags)</dt> |
153 | <dd> |
154 | <dd> |
154 | <p>This will initialise the default event loop if it hasn't been initialised |
155 | <p>This will initialise the default event loop if it hasn't been initialised |
155 | yet and return it. If the default loop could not be initialised, returns |
156 | yet and return it. If the default loop could not be initialised, returns |