summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root>2010-10-21 02:33:08 +0000
committerroot <root>2010-10-21 02:33:08 +0000
commited35fe84c2d1d72e35a7fd111834678b030f2023 (patch)
tree79f7f573745ddfdb853cf209918da6e2391d9174
parent015897f2e00ab95c7acd36afb5d381ffbdbe0c70 (diff)
*** empty log message ***
-rw-r--r--Changes4
-rw-r--r--ev++.h3
-rw-r--r--ev.c2
-rw-r--r--ev.h2
-rw-r--r--ev.pod25
5 files changed, 26 insertions, 10 deletions
diff --git a/Changes b/Changes
index 28fd4ed..ca668bd 100644
--- a/Changes
+++ b/Changes
@@ -3,6 +3,7 @@ Revision history for libev, a high-performance and full-featured event loop.
TODO: ABI??? API????? Changes???
TODO: include ev_xyz_start in each example?
TODO: section watcher states/lifetime
+TODO: ALL ev_xxx_set funtions must be called from ev++ set methods, somehow.
- "PORTING FROM LIBEV 3.X TO 4.X" (in ev.pod) is recommended reading.
- ev_embed_stop did not correctly stop the watcher (very good
testcase by Vladimir Timofeev).
@@ -14,6 +15,9 @@ TODO: section watcher states/lifetime
seems the former is *much* faster than the latter.
- reduce the number of spurious wake-ups with the ports backend.
- remove dependency on sys/queue.h on freebsd (patch by Vanilla Hsu).
+ - do async init within ev_async_start, not ev_async_set, which avoids
+ an API quirk where the set function must be called in the C++ API
+ even when there is nothing to set.
- add (undocumented) EV_ENABLE when adding events with kqueue,
this might help with OS X, which seems to need it despite documenting
not to need it (helpfully pointed out by Tilghman Lesher).
diff --git a/ev++.h b/ev++.h
index 19d9cd2..6c844fe 100644
--- a/ev++.h
+++ b/ev++.h
@@ -415,6 +415,7 @@ namespace ev {
#if EV_MULTIPLICITY
EV_PX;
+ // loop set
void set (EV_P) throw ()
{
this->EV_A = EV_A;
@@ -783,8 +784,6 @@ namespace ev {
#if EV_ASYNC_ENABLE
EV_BEGIN_WATCHER (async, async)
- void set () throw () { }
-
void send () throw ()
{
ev_async_send (EV_A_ static_cast<ev_async *>(this));
diff --git a/ev.c b/ev.c
index 9aed426..6bd4284 100644
--- a/ev.c
+++ b/ev.c
@@ -3579,6 +3579,8 @@ ev_async_start (EV_P_ ev_async *w)
if (expect_false (ev_is_active (w)))
return;
+ w->sent = 0;
+
evpipe_init (EV_A);
EV_FREQUENT_CHECK;
diff --git a/ev.h b/ev.h
index 20dbc10..fb9056b 100644
--- a/ev.h
+++ b/ev.h
@@ -642,7 +642,7 @@ void ev_resume (EV_P);
#define ev_check_set(ev) /* nop, yes, this is a serious in-joke */
#define ev_embed_set(ev,other_) do { (ev)->other = (other_); } while (0)
#define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */
-#define ev_async_set(ev) do { (ev)->sent = 0; } while (0)
+#define ev_async_set(ev) /* nop, yes, this is a serious in-joke */
#define ev_io_init(ev,cb,fd,events) do { ev_init ((ev), (cb)); ev_io_set ((ev),(fd),(events)); } while (0)
#define ev_timer_init(ev,cb,after,repeat) do { ev_init ((ev), (cb)); ev_timer_set ((ev),(after),(repeat)); } while (0)
diff --git a/ev.pod b/ev.pod
index b370558..2f405b5 100644
--- a/ev.pod
+++ b/ev.pod
@@ -3393,16 +3393,22 @@ do this when the watcher is inactive (and not pending either).
=item w->set ([arguments])
-Basically the same as C<ev_TYPE_set>, with the same arguments. Must be
-called at least once. Unlike the C counterpart, an active watcher gets
-automatically stopped and restarted when reconfiguring it with this
-method.
+Basically the same as C<ev_TYPE_set>, with the same arguments. Either this
+method or a suitable start method must be called at least once. Unlike the
+C counterpart, an active watcher gets automatically stopped and restarted
+when reconfiguring it with this method.
=item w->start ()
Starts the watcher. Note that there is no C<loop> argument, as the
constructor already stores the event loop.
+=item w->start ([arguments])
+
+Instead of calling C<set> and C<start> methods separately, it is often
+convenient to wrap them in one call. Uses the same type of arguments as
+the configure C<set> method of the watcher.
+
=item w->stop ()
Stops the watcher if it is active. Again, no C<loop> argument.
@@ -3424,20 +3430,25 @@ Invokes C<ev_stat_stat>.
=back
-Example: Define a class with an IO and idle watcher, start one of them in
-the constructor.
+Example: Define a class with two I/O and idle watchers, start the I/O
+watchers in the constructor.
class myclass
{
ev::io io ; void io_cb (ev::io &w, int revents);
+ ev::io2 io2 ; void io2_cb (ev::io &w, int revents);
ev::idle idle; void idle_cb (ev::idle &w, int revents);
myclass (int fd)
{
io .set <myclass, &myclass::io_cb > (this);
+ io2 .set <myclass, &myclass::io2_cb > (this);
idle.set <myclass, &myclass::idle_cb> (this);
- io.start (fd, ev::READ);
+ io.set (fd, ev::WRITE); // configure the watcher
+ io.start (); // start it whenever convenient
+
+ io2.start (fd, ev::READ); // set + start in one call
}
};