From c7703db989c22be0c1b8007acdbf2a84eb519a65 Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Tue, 4 Aug 2015 17:50:36 +0800 Subject: [PATCH] EventSocket: Add new event type pipe support Signed-off-by: Haomai Wang --- src/common/event_socket.h | 20 +++++++++++++++----- src/include/event_type.h | 3 ++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/common/event_socket.h b/src/common/event_socket.h index f2ac92de5b39a..7bbd7ec33e25f 100644 --- a/src/common/event_socket.h +++ b/src/common/event_socket.h @@ -25,17 +25,27 @@ class EventSocket { EventSocket(): socket(-1), type(EVENT_SOCKET_TYPE_NONE) {} bool is_valid() const { return socket != -1; } int init(int fd, int t) { + switch (t) { + case EVENT_SOCKET_TYPE_PIPE: #ifdef HAVE_EVENTFD - if (t == EVENT_SOCKET_TYPE_EVENTFD) { - socket = fd; - type = t; - return 0; - } + case EVENT_SOCKET_TYPE_EVENTFD: #endif + { + socket = fd; + type = t; + return 0; + } + } return -1; } int notify() { switch (type) { + case EVENT_SOCKET_TYPE_PIPE: + { + char buf[1]; + buf[0] = 'i'; + return write(socket, buf, 1); + } case EVENT_SOCKET_TYPE_EVENTFD: { uint64_t value = 1; diff --git a/src/include/event_type.h b/src/include/event_type.h index adab6907227ab..696e7664b3a18 100644 --- a/src/include/event_type.h +++ b/src/include/event_type.h @@ -16,6 +16,7 @@ #define CEPH_COMMON_EVENT_TYPE_H #define EVENT_SOCKET_TYPE_NONE 0 -#define EVENT_SOCKET_TYPE_EVENTFD 1 +#define EVENT_SOCKET_TYPE_PIPE 1 +#define EVENT_SOCKET_TYPE_EVENTFD 2 #endif -- 2.39.5