You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2014/12/25 22:05:58 UTC

[07/12] mesos git commit: Introduce libevent poll implementation.

Introduce libevent poll implementation.

Review: https://reviews.apache.org/r/28323


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/f4a41805
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/f4a41805
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/f4a41805

Branch: refs/heads/master
Commit: f4a41805774afb658cfd30c1b280599448e00b1b
Parents: a027dd1
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Sat Dec 20 12:43:54 2014 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Thu Dec 25 11:54:12 2014 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/Makefile.am           |  3 +-
 3rdparty/libprocess/src/libevent_poll.cpp | 74 ++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f4a41805/3rdparty/libprocess/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/Makefile.am b/3rdparty/libprocess/Makefile.am
index b95c0a9..09fce46 100644
--- a/3rdparty/libprocess/Makefile.am
+++ b/3rdparty/libprocess/Makefile.am
@@ -60,7 +60,8 @@ libprocess_la_CPPFLAGS =		\
 if ENABLE_LIBEVENT
 libprocess_la_SOURCES +=	\
     src/libevent.hpp		\
-    src/libevent.cpp
+    src/libevent.cpp		\
+    src/libevent_poll.cpp
 else
   libprocess_la_SOURCES +=	\
     src/libev.hpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/f4a41805/3rdparty/libprocess/src/libevent_poll.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/libevent_poll.cpp b/3rdparty/libprocess/src/libevent_poll.cpp
new file mode 100644
index 0000000..d0b8946
--- /dev/null
+++ b/3rdparty/libprocess/src/libevent_poll.cpp
@@ -0,0 +1,74 @@
+#include <event2/event.h>
+
+#include <process/future.hpp>
+#include <process/io.hpp>
+#include <process/process.hpp> // For process::initialize.
+
+#include "libevent.hpp"
+
+namespace process {
+
+namespace io {
+namespace internal {
+
+struct Poll
+{
+  Promise<short> promise;
+  event* ev;
+};
+
+
+void pollCallback(evutil_socket_t, short what, void* arg)
+{
+  Poll* poll = reinterpret_cast<Poll*>(arg);
+
+  if (poll->promise.future().hasDiscard()) {
+    poll->promise.discard();
+  } else {
+    // Convert libevent specific EV_READ / EV_WRITE to io::* specific
+    // values of these enumerations.
+    short events =
+      ((what & EV_READ) ? io::READ : 0) | ((what & EV_WRITE) ? io::WRITE : 0);
+
+    poll->promise.set(events);
+  }
+
+  event_free(poll->ev);
+  delete poll;
+}
+
+
+void pollDiscard(event* ev)
+{
+  event_active(ev, EV_READ, 0);
+}
+
+} // namespace internal {
+
+
+Future<short> poll(int fd, short events)
+{
+  process::initialize();
+
+  internal::Poll* poll = new internal::Poll();
+
+  Future<short> future = poll->promise.future();
+
+  // Convert io::READ / io::WRITE to libevent specific values of these
+  // enumerations.
+  short what =
+    ((events & io::READ) ? EV_READ : 0) | ((events & io::WRITE) ? EV_WRITE : 0);
+
+  poll->ev = event_new(base, fd, what, &internal::pollCallback, poll);
+  if (poll->ev == NULL) {
+    LOG(FATAL) << "Failed to poll, event_new";
+  }
+
+  event_add(poll->ev, NULL);
+
+  return future
+    .onDiscard(lambda::bind(&internal::pollDiscard, poll->ev));
+}
+
+} // namespace io {
+} // namespace process {