From d62943221d916737d52e83db662e6a1e2f92db0a Mon Sep 17 00:00:00 2001 From: root Date: Tue, 27 Nov 2007 20:38:07 +0000 Subject: [PATCH] *** empty log message *** --- ev.3 | 45 ++++++++++++++++++++++++++++++++---- ev.html | 72 +++++++++++++++++++++++++++++++++++++++------------------ ev.pod | 35 +++++++++++++++++++++++++--- 3 files changed, 123 insertions(+), 29 deletions(-) diff --git a/ev.3 b/ev.3 index a2e0946..979b314 100644 --- a/ev.3 +++ b/ev.3 @@ -858,8 +858,8 @@ events but its callback has not yet been invoked). As long as a watcher is pending (but not active) you must not call an init function on it (but \&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe) and you must make sure the watcher is available to libev (e.g. you cnanot \f(CW\*(C`free ()\*(C'\fR it). -.IP "callback = ev_cb (ev_TYPE *watcher)" 4 -.IX Item "callback = ev_cb (ev_TYPE *watcher)" +.IP "callback ev_cb (ev_TYPE *watcher)" 4 +.IX Item "callback ev_cb (ev_TYPE *watcher)" Returns the callback currently set on the watcher. .IP "ev_cb_set (ev_TYPE *watcher, callback)" 4 .IX Item "ev_cb_set (ev_TYPE *watcher, callback)" @@ -895,8 +895,45 @@ can cast it back to your own type: \& } .Ve .PP -More interesting and less C\-conformant ways of catsing your callback type -have been omitted.... +More interesting and less C\-conformant ways of casting your callback type +instead have been omitted. +.PP +Another common scenario is having some data structure with multiple +watchers: +.PP +.Vb 6 +\& struct my_biggy +\& { +\& int some_data; +\& ev_timer t1; +\& ev_timer t2; +\& } +.Ve +.PP +In this case getting the pointer to \f(CW\*(C`my_biggy\*(C'\fR is a bit more complicated, +you need to use \f(CW\*(C`offsetof\*(C'\fR: +.PP +.Vb 1 +\& #include +.Ve +.PP +.Vb 6 +\& static void +\& t1_cb (EV_P_ struct ev_timer *w, int revents) +\& { +\& struct my_biggy big = (struct my_biggy * +\& (((char *)w) - offsetof (struct my_biggy, t1)); +\& } +.Ve +.PP +.Vb 6 +\& static void +\& t2_cb (EV_P_ struct ev_timer *w, int revents) +\& { +\& struct my_biggy big = (struct my_biggy * +\& (((char *)w) - offsetof (struct my_biggy, t2)); +\& } +.Ve .SH "WATCHER TYPES" .IX Header "WATCHER TYPES" This section describes each watcher in detail, but will not repeat diff --git a/ev.html b/ev.html index 011cda6..a107da8 100644 --- a/ev.html +++ b/ev.html @@ -6,7 +6,7 @@ - + @@ -62,19 +62,19 @@
-

NAME

Top

+

NAME

libev - a high performance full-featured event loop written in C

-

SYNOPSIS

Top

+

SYNOPSIS

  #include <ev.h>
 
 
-

EXAMPLE PROGRAM

Top

+

EXAMPLE PROGRAM

  #include <ev.h>
 
@@ -119,7 +119,7 @@
 
-

DESCRIPTION

Top

+

DESCRIPTION

Libev is an event loop: you register interest in certain events (such as a file descriptor being readable or a timeout occuring), and it will manage @@ -133,7 +133,7 @@ details of the event, and then hand it over to libev by starting the watcher.

-

FEATURES

Top

+

FEATURES

Libev supports select, poll, the linux-specific epoll, the bsd-specific kqueue and the solaris-specific event port mechanisms @@ -149,7 +149,7 @@ file watchers (ev_stat) and even limited support for fork events for example).

-

CONVENTIONS

Top

+

CONVENTIONS

Libev is very configurable. In this manual the default configuration will be described, which supports multiple event loops. For more info about @@ -159,7 +159,7 @@ loops, then all functions taking an initial argument of name loop (which is always of type struct ev_loop *) will not have this argument.

-

TIME REPRESENTATION

Top

+

TIME REPRESENTATION

Libev represents time as a single floating point number, representing the (fractional) number of seconds since the (POSIX) epoch (somewhere near @@ -169,7 +169,7 @@ to the double type in C, and when you need to do any calculations o it, you should treat it as such.

-

GLOBAL FUNCTIONS

Top

+

GLOBAL FUNCTIONS

These functions can be called anytime, even before initialising the library in any way.

@@ -287,7 +287,7 @@ requested operation, or, if the condition doesn't go away, do bad stuff
-

FUNCTIONS CONTROLLING THE EVENT LOOP

Top

+

FUNCTIONS CONTROLLING THE EVENT LOOP

An event loop is described by a struct ev_loop *. The library knows two types of such loops, the default loop, which supports signals and child @@ -570,7 +570,7 @@ running when nothing else is active.

-

ANATOMY OF A WATCHER

Top

+

ANATOMY OF A WATCHER

A watcher is a structure that you create and register to record your interest in some event. For instance, if you want to wait for STDIN to @@ -743,7 +743,7 @@ is pending (but not active) you must not call an init function on it (but ev_TYPE_set is safe) and you must make sure the watcher is available to libev (e.g. you cnanot free () it).

-
callback = ev_cb (ev_TYPE *watcher)
+
callback ev_cb (ev_TYPE *watcher)

Returns the callback currently set on the watcher.

@@ -785,15 +785,43 @@ can cast it back to your own type:

} -

More interesting and less C-conformant ways of catsing your callback type -have been omitted....

+

More interesting and less C-conformant ways of casting your callback type +instead have been omitted.

+

Another common scenario is having some data structure with multiple +watchers:

+
  struct my_biggy
+  {
+    int some_data;
+    ev_timer t1;
+    ev_timer t2;
+  }
 
+
+

In this case getting the pointer to my_biggy is a bit more complicated, +you need to use offsetof:

+
  #include <stddef.h>
 
+  static void
+  t1_cb (EV_P_ struct ev_timer *w, int revents)
+  {
+    struct my_biggy big = (struct my_biggy *
+      (((char *)w) - offsetof (struct my_biggy, t1));
+  }
+
+  static void
+  t2_cb (EV_P_ struct ev_timer *w, int revents)
+  {
+    struct my_biggy big = (struct my_biggy *
+      (((char *)w) - offsetof (struct my_biggy, t2));
+  }
 
 
 
+
+
+
-

WATCHER TYPES

Top

+

WATCHER TYPES

This section describes each watcher in detail, but will not repeat information given in the last section. Any initialisation/set macros, @@ -1562,7 +1590,7 @@ believe me.

-

OTHER FUNCTIONS

Top

+

OTHER FUNCTIONS

There are some other functions of possible interest. Described. Here. Now.

@@ -1619,7 +1647,7 @@ loop!).

-

LIBEVENT EMULATION

Top

+

LIBEVENT EMULATION

Libev offers a compatibility emulation layer for libevent. It cannot emulate the internals of libevent, so here are some usage hints:

@@ -1639,7 +1667,7 @@ to use the libev header file and library.
-

C++ SUPPORT

Top

+

C++ SUPPORT

Libev comes with some simplistic wrapper classes for C++ that mainly allow you to use some convinience methods to start/stop watchers and also change @@ -1744,7 +1772,7 @@ the constructor.

-

MACRO MAGIC

Top

+

MACRO MAGIC

Libev can be compiled with a variety of options, the most fundemantal is EV_MULTIPLICITY. This option determines wether (most) functions and @@ -1805,7 +1833,7 @@ wether multiple loops are supported or not.

-

EMBEDDING

Top

+

EMBEDDING

Libev can (and often is) directly embedded into host applications. Examples of applications that embed it include the Deliantra @@ -2109,7 +2137,7 @@ that everybody includes and which overrides some autoconf choices:

-

COMPLEXITIES

Top

+

COMPLEXITIES

In this section the complexities of (many of) the algorithms used inside libev will be explained. For complexity discussions about backends see the @@ -2132,7 +2160,7 @@ documentation for ev_default_init.

-

AUTHOR

Top

+

AUTHOR

Marc Lehmann <libev@schmorp.de>.

diff --git a/ev.pod b/ev.pod index 1b797df..cac8de1 100644 --- a/ev.pod +++ b/ev.pod @@ -705,7 +705,7 @@ is pending (but not active) you must not call an init function on it (but C is safe) and you must make sure the watcher is available to libev (e.g. you cnanot C it). -=item callback = ev_cb (ev_TYPE *watcher) +=item callback ev_cb (ev_TYPE *watcher) Returns the callback currently set on the watcher. @@ -743,8 +743,37 @@ can cast it back to your own type: ... } -More interesting and less C-conformant ways of catsing your callback type -have been omitted.... +More interesting and less C-conformant ways of casting your callback type +instead have been omitted. + +Another common scenario is having some data structure with multiple +watchers: + + struct my_biggy + { + int some_data; + ev_timer t1; + ev_timer t2; + } + +In this case getting the pointer to C is a bit more complicated, +you need to use C: + + #include + + static void + t1_cb (EV_P_ struct ev_timer *w, int revents) + { + struct my_biggy big = (struct my_biggy * + (((char *)w) - offsetof (struct my_biggy, t1)); + } + + static void + t2_cb (EV_P_ struct ev_timer *w, int revents) + { + struct my_biggy big = (struct my_biggy * + (((char *)w) - offsetof (struct my_biggy, t2)); + } =head1 WATCHER TYPES -- 2.43.0