… | |
… | |
124 | this argument. |
124 | this argument. |
125 | |
125 | |
126 | =head2 TIME REPRESENTATION |
126 | =head2 TIME REPRESENTATION |
127 | |
127 | |
128 | Libev represents time as a single floating point number, representing |
128 | Libev represents time as a single floating point number, representing |
129 | the (fractional) number of seconds since the (POSIX) epoch (in practise |
129 | the (fractional) number of seconds since the (POSIX) epoch (in practice |
130 | somewhere near the beginning of 1970, details are complicated, don't |
130 | somewhere near the beginning of 1970, details are complicated, don't |
131 | ask). This type is called C<ev_tstamp>, which is what you should use |
131 | ask). This type is called C<ev_tstamp>, which is what you should use |
132 | too. It usually aliases to the C<double> type in C. When you need to do |
132 | too. It usually aliases to the C<double> type in C. When you need to do |
133 | any calculations on it, you should treat it as some floating point value. |
133 | any calculations on it, you should treat it as some floating point value. |
134 | |
134 | |
… | |
… | |
165 | |
165 | |
166 | =item ev_tstamp ev_time () |
166 | =item ev_tstamp ev_time () |
167 | |
167 | |
168 | Returns the current time as libev would use it. Please note that the |
168 | Returns the current time as libev would use it. Please note that the |
169 | C<ev_now> function is usually faster and also often returns the timestamp |
169 | C<ev_now> function is usually faster and also often returns the timestamp |
170 | you actually want to know. |
170 | you actually want to know. Also interetsing is the combination of |
|
|
171 | C<ev_update_now> and C<ev_now>. |
171 | |
172 | |
172 | =item ev_sleep (ev_tstamp interval) |
173 | =item ev_sleep (ev_tstamp interval) |
173 | |
174 | |
174 | Sleep for the given interval: The current thread will be blocked until |
175 | Sleep for the given interval: The current thread will be blocked until |
175 | either it is interrupted or the given time interval has passed. Basically |
176 | either it is interrupted or the given time interval has passed. Basically |
… | |
… | |
213 | assert (("sorry, no epoll, no sex", |
214 | assert (("sorry, no epoll, no sex", |
214 | ev_supported_backends () & EVBACKEND_EPOLL)); |
215 | ev_supported_backends () & EVBACKEND_EPOLL)); |
215 | |
216 | |
216 | =item unsigned int ev_recommended_backends () |
217 | =item unsigned int ev_recommended_backends () |
217 | |
218 | |
218 | Return the set of all backends compiled into this binary of libev and also |
219 | Return the set of all backends compiled into this binary of libev and |
219 | recommended for this platform. This set is often smaller than the one |
220 | also recommended for this platform, meaning it will work for most file |
|
|
221 | descriptor types. This set is often smaller than the one returned by |
220 | returned by C<ev_supported_backends>, as for example kqueue is broken on |
222 | C<ev_supported_backends>, as for example kqueue is broken on most BSDs |
221 | most BSDs and will not be auto-detected unless you explicitly request it |
223 | and will not be auto-detected unless you explicitly request it (assuming |
222 | (assuming you know what you are doing). This is the set of backends that |
224 | you know what you are doing). This is the set of backends that libev will |
223 | libev will probe for if you specify no backends explicitly. |
225 | probe for if you specify no backends explicitly. |
224 | |
226 | |
225 | =item unsigned int ev_embeddable_backends () |
227 | =item unsigned int ev_embeddable_backends () |
226 | |
228 | |
227 | Returns the set of backends that are embeddable in other event loops. This |
229 | Returns the set of backends that are embeddable in other event loops. This |
228 | is the theoretical, all-platform, value. To find which backends |
230 | value is platform-specific but can include backends not available on the |
229 | might be supported on the current system, you would need to look at |
231 | current system. To find which embeddable backends might be supported on |
230 | C<ev_embeddable_backends () & ev_supported_backends ()>, likewise for |
232 | the current system, you would need to look at C<ev_embeddable_backends () |
231 | recommended ones. |
233 | & ev_supported_backends ()>, likewise for recommended ones. |
232 | |
234 | |
233 | See the description of C<ev_embed> watchers for more info. |
235 | See the description of C<ev_embed> watchers for more info. |
234 | |
236 | |
235 | =item ev_set_allocator (void *(*cb)(void *ptr, long size)) [NOT REENTRANT] |
237 | =item ev_set_allocator (void *(*cb)(void *ptr, long size)) [NOT REENTRANT] |
236 | |
238 | |
… | |
… | |
4531 | =head3 C<kqueue> is buggy |
4533 | =head3 C<kqueue> is buggy |
4532 | |
4534 | |
4533 | The kqueue syscall is broken in all known versions - most versions support |
4535 | The kqueue syscall is broken in all known versions - most versions support |
4534 | only sockets, many support pipes. |
4536 | only sockets, many support pipes. |
4535 | |
4537 | |
4536 | Libev tries to work around this by not using C<kqueue> by default on |
4538 | Libev tries to work around this by not using C<kqueue> by default on this |
4537 | this rotten platform, but of course you can still ask for it when creating |
4539 | rotten platform, but of course you can still ask for it when creating a |
4538 | a loop. |
4540 | loop - embedding a socket-only kqueue loop into a select-based one is |
|
|
4541 | probably going to work well. |
4539 | |
4542 | |
4540 | =head3 C<poll> is buggy |
4543 | =head3 C<poll> is buggy |
4541 | |
4544 | |
4542 | Instead of fixing C<kqueue>, Apple replaced their (working) C<poll> |
4545 | Instead of fixing C<kqueue>, Apple replaced their (working) C<poll> |
4543 | implementation by something calling C<kqueue> internally around the 10.5.6 |
4546 | implementation by something calling C<kqueue> internally around the 10.5.6 |
… | |
… | |
4562 | |
4565 | |
4563 | =head3 C<errno> reentrancy |
4566 | =head3 C<errno> reentrancy |
4564 | |
4567 | |
4565 | The default compile environment on Solaris is unfortunately so |
4568 | The default compile environment on Solaris is unfortunately so |
4566 | thread-unsafe that you can't even use components/libraries compiled |
4569 | thread-unsafe that you can't even use components/libraries compiled |
4567 | without C<-D_REENTRANT> (as long as they use C<errno>), which, of course, |
4570 | without C<-D_REENTRANT> in a threaded program, which, of course, isn't |
4568 | isn't defined by default. |
4571 | defined by default. A valid, if stupid, implementation choice. |
4569 | |
4572 | |
4570 | If you want to use libev in threaded environments you have to make sure |
4573 | If you want to use libev in threaded environments you have to make sure |
4571 | it's compiled with C<_REENTRANT> defined. |
4574 | it's compiled with C<_REENTRANT> defined. |
4572 | |
4575 | |
4573 | =head3 Event port backend |
4576 | =head3 Event port backend |
4574 | |
4577 | |
4575 | The scalable event interface for Solaris is called "event ports". Unfortunately, |
4578 | The scalable event interface for Solaris is called "event |
4576 | this mechanism is very buggy. If you run into high CPU usage, your program |
4579 | ports". Unfortunately, this mechanism is very buggy in all major |
|
|
4580 | releases. If you run into high CPU usage, your program freezes or you get |
4577 | freezes or you get a large number of spurious wakeups, make sure you have |
4581 | a large number of spurious wakeups, make sure you have all the relevant |
4578 | all the relevant and latest kernel patches applied. No, I don't know which |
4582 | and latest kernel patches applied. No, I don't know which ones, but there |
4579 | ones, but there are multiple ones. |
4583 | are multiple ones to apply, and afterwards, event ports actually work |
|
|
4584 | great. |
4580 | |
4585 | |
4581 | If you can't get it to work, you can try running the program by setting |
4586 | If you can't get it to work, you can try running the program by setting |
4582 | the environment variable C<LIBEV_FLAGS=3> to only allow C<poll> and |
4587 | the environment variable C<LIBEV_FLAGS=3> to only allow C<poll> and |
4583 | C<select> backends. |
4588 | C<select> backends. |
4584 | |
4589 | |
4585 | =head2 AIX POLL BUG |
4590 | =head2 AIX POLL BUG |
4586 | |
4591 | |
4587 | AIX unfortunately has a broken C<poll.h> header. Libev works around |
4592 | AIX unfortunately has a broken C<poll.h> header. Libev works around |
4588 | this by trying to avoid the poll backend altogether (i.e. it's not even |
4593 | this by trying to avoid the poll backend altogether (i.e. it's not even |
4589 | compiled in), which normally isn't a big problem as C<select> works fine |
4594 | compiled in), which normally isn't a big problem as C<select> works fine |
4590 | with large bitsets, and AIX is dead anyway. |
4595 | with large bitsets on AIX, and AIX is dead anyway. |
4591 | |
4596 | |
4592 | =head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS |
4597 | =head2 WIN32 PLATFORM LIMITATIONS AND WORKAROUNDS |
4593 | |
4598 | |
4594 | =head3 General issues |
4599 | =head3 General issues |
4595 | |
4600 | |
… | |
… | |
4872 | |
4877 | |
4873 | =over 4 |
4878 | =over 4 |
4874 | |
4879 | |
4875 | =item active |
4880 | =item active |
4876 | |
4881 | |
4877 | A watcher is active as long as it has been started (has been attached to |
4882 | A watcher is active as long as it has been started and not yet stopped. |
4878 | an event loop) but not yet stopped (disassociated from the event loop). |
4883 | See L<WATCHER STATES> for details. |
4879 | |
4884 | |
4880 | =item application |
4885 | =item application |
4881 | |
4886 | |
4882 | In this document, an application is whatever is using libev. |
4887 | In this document, an application is whatever is using libev. |
|
|
4888 | |
|
|
4889 | =item backend |
|
|
4890 | |
|
|
4891 | The part of the code dealing with the operating system interfaces. |
4883 | |
4892 | |
4884 | =item callback |
4893 | =item callback |
4885 | |
4894 | |
4886 | The address of a function that is called when some event has been |
4895 | The address of a function that is called when some event has been |
4887 | detected. Callbacks are being passed the event loop, the watcher that |
4896 | detected. Callbacks are being passed the event loop, the watcher that |
4888 | received the event, and the actual event bitset. |
4897 | received the event, and the actual event bitset. |
4889 | |
4898 | |
4890 | =item callback invocation |
4899 | =item callback/watcher invocation |
4891 | |
4900 | |
4892 | The act of calling the callback associated with a watcher. |
4901 | The act of calling the callback associated with a watcher. |
4893 | |
4902 | |
4894 | =item event |
4903 | =item event |
4895 | |
4904 | |
… | |
… | |
4914 | The model used to describe how an event loop handles and processes |
4923 | The model used to describe how an event loop handles and processes |
4915 | watchers and events. |
4924 | watchers and events. |
4916 | |
4925 | |
4917 | =item pending |
4926 | =item pending |
4918 | |
4927 | |
4919 | A watcher is pending as soon as the corresponding event has been detected, |
4928 | A watcher is pending as soon as the corresponding event has been |
4920 | and stops being pending as soon as the watcher will be invoked or its |
4929 | detected. See L<WATCHER STATES> for details. |
4921 | pending status is explicitly cleared by the application. |
|
|
4922 | |
|
|
4923 | A watcher can be pending, but not active. Stopping a watcher also clears |
|
|
4924 | its pending status. |
|
|
4925 | |
4930 | |
4926 | =item real time |
4931 | =item real time |
4927 | |
4932 | |
4928 | The physical time that is observed. It is apparently strictly monotonic :) |
4933 | The physical time that is observed. It is apparently strictly monotonic :) |
4929 | |
4934 | |
… | |
… | |
4936 | =item watcher |
4941 | =item watcher |
4937 | |
4942 | |
4938 | A data structure that describes interest in certain events. Watchers need |
4943 | A data structure that describes interest in certain events. Watchers need |
4939 | to be started (attached to an event loop) before they can receive events. |
4944 | to be started (attached to an event loop) before they can receive events. |
4940 | |
4945 | |
4941 | =item watcher invocation |
|
|
4942 | |
|
|
4943 | The act of calling the callback associated with a watcher. |
|
|
4944 | |
|
|
4945 | =back |
4946 | =back |
4946 | |
4947 | |
4947 | =head1 AUTHOR |
4948 | =head1 AUTHOR |
4948 | |
4949 | |
4949 | Marc Lehmann <libev@schmorp.de>, with repeated corrections by Mikael Magnusson. |
4950 | Marc Lehmann <libev@schmorp.de>, with repeated corrections by Mikael Magnusson. |