summaryrefslogtreecommitdiffstats
path: root/base/message_pump_libevent.cc
diff options
context:
space:
mode:
authorjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-08 17:36:06 +0000
committerjeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-08 17:36:06 +0000
commit1d2eb13fa0a3e8b1e03a22b8dd4d2af38b85b626 (patch)
tree61a73bac98aade2aaeb07e342529f53b5dc41265 /base/message_pump_libevent.cc
parent118e6963e97ca9fa971589295742ff33b4073e47 (diff)
downloadchromium_src-1d2eb13fa0a3e8b1e03a22b8dd4d2af38b85b626.zip
chromium_src-1d2eb13fa0a3e8b1e03a22b8dd4d2af38b85b626.tar.gz
chromium_src-1d2eb13fa0a3e8b1e03a22b8dd4d2af38b85b626.tar.bz2
Add FD watching support to message_pump_libevent.
This CL goes along the same lines as the WatchSocket code, but we really need better encapsulation for this class in generel. Review URL: http://codereview.chromium.org/13129 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6513 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_libevent.cc')
-rw-r--r--base/message_pump_libevent.cc43
1 files changed, 39 insertions, 4 deletions
diff --git a/base/message_pump_libevent.cc b/base/message_pump_libevent.cc
index 0dd533e..a281980 100644
--- a/base/message_pump_libevent.cc
+++ b/base/message_pump_libevent.cc
@@ -26,7 +26,7 @@ static int SetNonBlocking(int fd)
// Called if a byte is received on the wakeup pipe.
void MessagePumpLibevent::OnWakeup(int socket, short flags, void* context) {
- base::MessagePumpLibevent* that =
+ base::MessagePumpLibevent* that =
static_cast<base::MessagePumpLibevent*>(context);
DCHECK(that->wakeup_pipe_out_ == socket);
@@ -60,7 +60,7 @@ bool MessagePumpLibevent::Init() {
wakeup_pipe_in_ = fds[1];
wakeup_event_ = new event;
- event_set(wakeup_event_, wakeup_pipe_out_, EV_READ | EV_PERSIST,
+ event_set(wakeup_event_, wakeup_pipe_out_, EV_READ | EV_PERSIST,
OnWakeup, this);
event_base_set(event_base_, wakeup_event_);
@@ -77,7 +77,7 @@ MessagePumpLibevent::~MessagePumpLibevent() {
event_base_free(event_base_);
}
-void MessagePumpLibevent::WatchSocket(int socket, short interest_mask,
+void MessagePumpLibevent::WatchSocket(int socket, short interest_mask,
event* e, Watcher* watcher) {
// Set current interest mask and message pump for this event
@@ -91,13 +91,36 @@ void MessagePumpLibevent::WatchSocket(int socket, short interest_mask,
NOTREACHED();
}
+void MessagePumpLibevent::WatchFileHandle(int fd, short interest_mask,
+ event* e, FileWatcher* watcher) {
+ // Set current interest mask and message pump for this event
+ if ((interest_mask & EV_READ) != 0) {
+ event_set(e, fd, interest_mask, OnFileReadReadinessNotification, watcher);
+ } else {
+ event_set(e, fd, interest_mask, OnFileWriteReadinessNotification, watcher);
+ }
+
+ // Tell libevent which message pump this fd will belong to when we add it.
+ event_base_set(event_base_, e);
+
+ // Add this fd to the list of monitored sockets.
+ if (event_add(e, NULL))
+ NOTREACHED();
+}
+
void MessagePumpLibevent::UnwatchSocket(event* e) {
// Remove this socket from the list of monitored sockets.
if (event_del(e))
NOTREACHED();
}
-void MessagePumpLibevent::OnReadinessNotification(int socket, short flags,
+void MessagePumpLibevent::UnwatchFileHandle(event* e) {
+ // Remove this fd from the list of monitored fds.
+ if (event_del(e))
+ NOTREACHED();
+}
+
+void MessagePumpLibevent::OnReadinessNotification(int socket, short flags,
void* context) {
// The given socket is ready for I/O.
// Tell the owner what kind of I/O the socket is ready for.
@@ -105,6 +128,18 @@ void MessagePumpLibevent::OnReadinessNotification(int socket, short flags,
watcher->OnSocketReady(flags);
}
+void MessagePumpLibevent::OnFileReadReadinessNotification(int fd, short flags,
+ void* context) {
+ FileWatcher* watcher = static_cast<FileWatcher*>(context);
+ watcher->OnFileReadReady(fd);
+}
+
+void MessagePumpLibevent::OnFileWriteReadinessNotification(int fd, short flags,
+ void* context) {
+ FileWatcher* watcher = static_cast<FileWatcher*>(context);
+ watcher->OnFileWriteReady(fd);
+}
+
// Reentrant!
void MessagePumpLibevent::Run(Delegate* delegate) {
DCHECK(keep_running_) << "Quit must have been called outside of Run!";