summaryrefslogtreecommitdiff
path: root/ev.c
diff options
context:
space:
mode:
authorroot <root>2007-11-23 19:13:33 +0000
committerroot <root>2007-11-23 19:13:33 +0000
commit6e0418ec92a0b2bfbbe75790bb015bcd022f5dad (patch)
tree2544b9af420d250c6d31be66ca2ff9f46b58eef5 /ev.c
parent4dc30d27d0b48de023a3e1e7fd67ac52273580d1 (diff)
first try at embed watchers
Diffstat (limited to 'ev.c')
-rw-r--r--ev.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/ev.c b/ev.c
index fd82fbd..d5ebdfc 100644
--- a/ev.c
+++ b/ev.c
@@ -399,6 +399,9 @@ ev_feed_event (EV_P_ void *w, int revents)
return;
}
+ if (expect_false (!w_->cb))
+ return;
+
w_->pending = ++pendingcnt [ABSPRI (w_)];
array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
@@ -818,6 +821,14 @@ ev_recommended_backends (void)
}
unsigned int
+ev_embeddable_backends (void)
+{
+ return EVBACKEND_EPOLL
+ | EVBACKEND_KQUEUE
+ | EVBACKEND_PORT;
+}
+
+unsigned int
ev_backend (EV_P)
{
return backend;
@@ -1661,6 +1672,44 @@ ev_child_stop (EV_P_ struct ev_child *w)
ev_stop (EV_A_ (W)w);
}
+#if EV_MULTIPLICITY
+static void
+embed_cb (EV_P_ struct ev_io *io, int revents)
+{
+ struct ev_embed *w = (struct ev_embed *)(((char *)io) - offsetof (struct ev_embed, io));
+
+ ev_feed_event (EV_A_ (W)w, EV_EMBED);
+ ev_loop (w->loop, EVLOOP_NONBLOCK);
+}
+
+void
+ev_embed_start (EV_P_ struct ev_embed *w)
+{
+ if (expect_false (ev_is_active (w)))
+ return;
+
+ {
+ struct ev_loop *loop = w->loop;
+ assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
+ ev_io_init (&w->io, embed_cb, backend_fd, EV_READ);
+ }
+
+ ev_io_start (EV_A_ &w->io);
+ ev_start (EV_A_ (W)w, 1);
+}
+
+void
+ev_embed_stop (EV_P_ struct ev_embed *w)
+{
+ ev_clear_pending (EV_A_ (W)w);
+ if (expect_false (!ev_is_active (w)))
+ return;
+
+ ev_io_stop (EV_A_ &w->io);
+ ev_stop (EV_A_ (W)w);
+}
+#endif
+
/*****************************************************************************/
struct ev_once