summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root>2007-12-08 14:27:38 +0000
committerroot <root>2007-12-08 14:27:38 +0000
commit57e6fe17689de1646a53a20a46374936391db3e2 (patch)
tree8db7b035c9650fe2f4042dc5749e724fda6fca76
parent480621758fe1687120978562a553920ed46e1b7e (diff)
fix c++ interface
-rw-r--r--ev++.h29
-rw-r--r--ev.333
-rw-r--r--ev.c21
-rw-r--r--ev.html29
-rw-r--r--ev.pod9
5 files changed, 85 insertions, 36 deletions
diff --git a/ev++.h b/ev++.h
index fea0ac1..71a3d52 100644
--- a/ev++.h
+++ b/ev++.h
@@ -22,10 +22,10 @@ namespace ev {
ev_init (this, 0);
}
- void set_ (void *object, void (*cb)(EV_P_ ev_watcher *w, int revents))
+ void set_ (void *data, void (*cb)(EV_P_ watcher *w, int revents))
{
- this->data = object;
- ev_set_cb (static_cast<ev_watcher *>(this), cb);
+ this->data = data;
+ ev_set_cb (static_cast<watcher *>(this), cb);
}
template<class K, void (K::*method)(watcher &w, int)>
@@ -35,11 +35,10 @@ namespace ev {
}
template<class K, void (K::*method)(watcher &w, int)>
- static void method_thunk (EV_P_ ev_watcher *w, int revents)
+ static void method_thunk (EV_P_ watcher *w, int revents)
{
- watcher *self = static_cast<watcher *>(w);
- K *obj = static_cast<K *>(self->data);
- (obj->*method) (*self, revents);
+ K *obj = static_cast<K *>(w->data);
+ (obj->*method) (*w, revents);
}
template<class K, void (K::*method)(watcher &w, int) const>
@@ -49,24 +48,22 @@ namespace ev {
}
template<class K, void (K::*method)(watcher &w, int) const>
- static void const_method_thunk (EV_P_ ev_watcher *w, int revents)
+ static void const_method_thunk (EV_P_ watcher *w, int revents)
{
- watcher *self = static_cast<watcher *>(w);
- K *obj = static_cast<K *>(self->data);
- (obj->*method) (*self, revents);
+ K *obj = static_cast<K *>(w->data);
+ (obj->*method) (*w, revents);
}
- template<void (*function)(watcher &w, int), void *data = 0>
- void set ()
+ template<void (*function)(watcher &w, int)>
+ void set (void *data = 0)
{
set_ (data, function_thunk<function>);
}
template<void (*function)(watcher &w, int)>
- static void function_thunk (EV_P_ ev_watcher *w, int revents)
+ static void function_thunk (EV_P_ watcher *w, int revents)
{
- watcher *self = static_cast<watcher *>(w);
- function (*self, revents);
+ function (*w, revents);
}
void operator ()(int events = EV_UNDEF)
diff --git a/ev.3 b/ev.3
index 1f33e81..8e5a19f 100644
--- a/ev.3
+++ b/ev.3
@@ -129,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title ""<STANDARD INPUT>" 1"
-.TH "<STANDARD INPUT>" 1 "2007-12-07" "perl v5.8.8" "User Contributed Perl Documentation"
+.TH "<STANDARD INPUT>" 1 "2007-12-08" "perl v5.8.8" "User Contributed Perl Documentation"
.SH "NAME"
libev \- a high performance full\-featured event loop written in C
.SH "SYNOPSIS"
@@ -891,8 +891,9 @@ it.
Returns a true value iff the watcher is pending, (i.e. it has outstanding
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).
+\&\f(CW\*(C`ev_TYPE_set\*(C'\fR is safe), you must not change its priority, and you must
+make sure the watcher is available to libev (e.g. you cannot \f(CW\*(C`free ()\*(C'\fR
+it).
.IP "callback ev_cb (ev_TYPE *watcher)" 4
.IX Item "callback ev_cb (ev_TYPE *watcher)"
Returns the callback currently set on the watcher.
@@ -920,12 +921,25 @@ watchers on the same event and make sure one is called first.
If you need to suppress invocation when higher priority events are pending
you need to look at \f(CW\*(C`ev_idle\*(C'\fR watchers, which provide this functionality.
.Sp
+You \fImust not\fR change the priority of a watcher as long as it is active or
+pending.
+.Sp
The default priority used by watchers when no priority has been set is
always \f(CW0\fR, which is supposed to not be too high and not be too low :).
.Sp
Setting a priority outside the range of \f(CW\*(C`EV_MINPRI\*(C'\fR to \f(CW\*(C`EV_MAXPRI\*(C'\fR is
fine, as long as you do not mind that the priority value you query might
or might not have been adjusted to be within valid range.
+.IP "ev_invoke (loop, ev_TYPE *watcher, int revents)" 4
+.IX Item "ev_invoke (loop, ev_TYPE *watcher, int revents)"
+Invoke the \f(CW\*(C`watcher\*(C'\fR with the given \f(CW\*(C`loop\*(C'\fR and \f(CW\*(C`revents\*(C'\fR. Neither
+\&\f(CW\*(C`loop\*(C'\fR nor \f(CW\*(C`revents\*(C'\fR need to be valid as long as the watcher callback
+can deal with that fact.
+.IP "int ev_clear_pending (loop, ev_TYPE *watcher)" 4
+.IX Item "int ev_clear_pending (loop, ev_TYPE *watcher)"
+If the watcher is pending, this function returns clears its pending status
+and returns its \f(CW\*(C`revents\*(C'\fR bitset (as if its callback was invoked). If the
+watcher isn't pending it does nothing and returns \f(CW0\fR.
.Sh "\s-1ASSOCIATING\s0 \s-1CUSTOM\s0 \s-1DATA\s0 \s-1WITH\s0 A \s-1WATCHER\s0"
.IX Subsection "ASSOCIATING CUSTOM DATA WITH A WATCHER"
Each watcher has, by default, a member \f(CW\*(C`void *data\*(C'\fR that you can change
@@ -1980,13 +1994,22 @@ Example: simple class declaration and watcher initialisation
\& ev::io iow;
\& iow.set <myclass, &myclass::io_cb> (&obj);
.Ve
-.IP "w\->set (void (*function)(watcher &w, int), void *data = 0)" 4
-.IX Item "w->set (void (*function)(watcher &w, int), void *data = 0)"
+.IP "w\->set<function> (void *data = 0)" 4
+.IX Item "w->set<function> (void *data = 0)"
Also sets a callback, but uses a static method or plain function as
callback. The optional \f(CW\*(C`data\*(C'\fR argument will be stored in the watcher's
\&\f(CW\*(C`data\*(C'\fR member and is free for you to use.
.Sp
+The prototype of the \f(CW\*(C`function\*(C'\fR must be \f(CW\*(C`void (*)(ev::TYPE &w, int)\*(C'\fR.
+.Sp
See the method\-\f(CW\*(C`set\*(C'\fR above for more details.
+.Sp
+Example:
+.Sp
+.Vb 2
+\& static void io_cb (ev::io &w, int revents) { }
+\& iow.set <io_cb> ();
+.Ve
.IP "w\->set (struct ev_loop *)" 4
.IX Item "w->set (struct ev_loop *)"
Associates a different \f(CW\*(C`struct ev_loop\*(C'\fR with this watcher. You can only
diff --git a/ev.c b/ev.c
index 7e9423e..dbda0b9 100644
--- a/ev.c
+++ b/ev.c
@@ -224,23 +224,24 @@ extern "C" {
#if __GNUC__ >= 3
# define expect(expr,value) __builtin_expect ((expr),(value))
-# define inline_size static inline /* inline for codesize */
-# if EV_MINIMAL
-# define noinline __attribute__ ((noinline))
-# define inline_speed static noinline
-# else
-# define noinline
-# define inline_speed static inline
-# endif
+# define noinline __attribute__ ((noinline))
#else
# define expect(expr,value) (expr)
-# define inline_speed static
-# define inline_size static
# define noinline
+# if __STDC_VERSION__ < 199901L
+# define inline
+# endif
#endif
#define expect_false(expr) expect ((expr) != 0, 0)
#define expect_true(expr) expect ((expr) != 0, 1)
+#define inline_size static inline
+
+#if EV_MINIMAL
+# define inline_speed static noinline
+#else
+# define inline_speed static inline
+#endif
#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
#define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
diff --git a/ev.html b/ev.html
index 738d6d0..d8909ea 100644
--- a/ev.html
+++ b/ev.html
@@ -6,7 +6,7 @@
<meta name="description" content="Pod documentation for libev" />
<meta name="inputfile" content="&lt;standard input&gt;" />
<meta name="outputfile" content="&lt;standard output&gt;" />
- <meta name="created" content="Fri Dec 7 21:19:14 2007" />
+ <meta name="created" content="Sat Dec 8 15:27:35 2007" />
<meta name="generator" content="Pod::Xhtml 1.57" />
<link rel="stylesheet" href="http://res.tst.eu/pod.css"/></head>
<body>
@@ -771,8 +771,9 @@ it.</p>
<p>Returns a true value iff the watcher is pending, (i.e. it has outstanding
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
-<code>ev_TYPE_set</code> is safe) and you must make sure the watcher is available to
-libev (e.g. you cnanot <code>free ()</code> it).</p>
+<code>ev_TYPE_set</code> is safe), you must not change its priority, and you must
+make sure the watcher is available to libev (e.g. you cannot <code>free ()</code>
+it).</p>
</dd>
<dt>callback ev_cb (ev_TYPE *watcher)</dt>
<dd>
@@ -797,12 +798,26 @@ example, to reduce latency after idling, or more often, to bind two
watchers on the same event and make sure one is called first.</p>
<p>If you need to suppress invocation when higher priority events are pending
you need to look at <code>ev_idle</code> watchers, which provide this functionality.</p>
+ <p>You <i>must not</i> change the priority of a watcher as long as it is active or
+pending.</p>
<p>The default priority used by watchers when no priority has been set is
always <code>0</code>, which is supposed to not be too high and not be too low :).</p>
<p>Setting a priority outside the range of <code>EV_MINPRI</code> to <code>EV_MAXPRI</code> is
fine, as long as you do not mind that the priority value you query might
or might not have been adjusted to be within valid range.</p>
</dd>
+ <dt>ev_invoke (loop, ev_TYPE *watcher, int revents)</dt>
+ <dd>
+ <p>Invoke the <code>watcher</code> with the given <code>loop</code> and <code>revents</code>. Neither
+<code>loop</code> nor <code>revents</code> need to be valid as long as the watcher callback
+can deal with that fact.</p>
+ </dd>
+ <dt>int ev_clear_pending (loop, ev_TYPE *watcher)</dt>
+ <dd>
+ <p>If the watcher is pending, this function returns clears its pending status
+and returns its <code>revents</code> bitset (as if its callback was invoked). If the
+watcher isn't pending it does nothing and returns <code>0</code>.</p>
+ </dd>
</dl>
@@ -1808,12 +1823,18 @@ thunking function, making it as fast as a direct C callback.</p>
</pre>
</dd>
- <dt>w-&gt;set (void (*function)(watcher &amp;w, int), void *data = 0)</dt>
+ <dt>w-&gt;set&lt;function&gt; (void *data = 0)</dt>
<dd>
<p>Also sets a callback, but uses a static method or plain function as
callback. The optional <code>data</code> argument will be stored in the watcher's
<code>data</code> member and is free for you to use.</p>
+ <p>The prototype of the <code>function</code> must be <code>void (*)(ev::TYPE &amp;w, int)</code>.</p>
<p>See the method-<code>set</code> above for more details.</p>
+ <p>Example:</p>
+<pre> static void io_cb (ev::io &amp;w, int revents) { }
+ iow.set &lt;io_cb&gt; ();
+
+</pre>
</dd>
<dt>w-&gt;set (struct ev_loop *)</dt>
<dd>
diff --git a/ev.pod b/ev.pod
index ef9892e..62118f1 100644
--- a/ev.pod
+++ b/ev.pod
@@ -1846,14 +1846,21 @@ Example: simple class declaration and watcher initialisation
ev::io iow;
iow.set <myclass, &myclass::io_cb> (&obj);
-=item w->set (void (*function)(watcher &w, int), void *data = 0)
+=item w->set<function> (void *data = 0)
Also sets a callback, but uses a static method or plain function as
callback. The optional C<data> argument will be stored in the watcher's
C<data> member and is free for you to use.
+The prototype of the C<function> must be C<void (*)(ev::TYPE &w, int)>.
+
See the method-C<set> above for more details.
+Example:
+
+ static void io_cb (ev::io &w, int revents) { }
+ iow.set <io_cb> ();
+
=item w->set (struct ev_loop *)
Associates a different C<struct ev_loop> with this watcher. You can only