Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: base/message_pump_libevent.h

Issue 14068: Reverting 6911. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_loop.cc ('k') | base/message_pump_libevent.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_pump_libevent.h
===================================================================
--- base/message_pump_libevent.h (revision 6915)
+++ base/message_pump_libevent.h (working copy)
@@ -6,7 +6,6 @@
#define BASE_MESSAGE_PUMP_LIBEVENT_H_
#include "base/message_pump.h"
-#include "base/scoped_ptr.h"
#include "base/time.h"
// Declare structs we need from libevent.h rather than including it
@@ -19,66 +18,47 @@
// TODO(dkegel): add support for background file IO somehow
class MessagePumpLibevent : public MessagePump {
public:
-
- // Object returned by WatchFileDescriptor to manage further watching.
- class FileDescriptorWatcher {
- public:
- FileDescriptorWatcher();
- ~FileDescriptorWatcher(); // Implicitly calls StopWatching.
-
- // NOTE: These methods aren't called StartWatching()/StopWatching() to
- // avoid confusion with the win32 ObjectWatcher class.
-
- // Stop watching the FD, always safe to call. No-op if there's nothing
- // to do.
- bool StopWatchingFileDescriptor();
-
- private:
- // Called by MessagePumpLibevent, ownership of |e| is transferred to this
- // object.
- // If this FileWatcher is already watching an event, the previous event is
- // terminated and cleaned up here.
- void Init(event* e, bool is_persistent);
- friend class MessagePumpLibevent;
-
- private:
- bool is_persistent_; // false if this event is one-shot.
- scoped_ptr<event> event_;
- DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher);
- };
-
- // Used with WatchFileDescptor to asynchronously monitor the I/O readiness of
- // a File Descriptor.
+ // Used with WatchSocket to asynchronously monitor the I/O readiness of a
+ // socket.
class Watcher {
public:
virtual ~Watcher() {}
- // Called from MessageLoop::Run when an FD can be read from/written to
- // without blocking
- virtual void OnFileCanReadWithoutBlocking(int fd) = 0;
- virtual void OnFileCanWriteWithoutBlocking(int fd) = 0;
+ // Called from MessageLoop::Run when a ready socket is detected.
+ virtual void OnSocketReady(short eventmask) = 0;
};
+ // Used with WatchFileHandle to monitor I/O readiness for a File Handle.
+ class FileWatcher {
+ public:
+ virtual ~FileWatcher() {}
+ // Called from MessageLoop::Run when a non-blocking read/write can be made.
+ virtual void OnFileReadReady(int fd) = 0;
+ virtual void OnFileWriteReady(int fd) = 0;
+ };
+
MessagePumpLibevent();
virtual ~MessagePumpLibevent();
- enum Mode {
- WATCH_READ,
- WATCH_WRITE,
- WATCH_READ_WRITE
- };
-
- // Have the current thread's message loop watch for a a situation in which
- // reading/writing to the FD can be performed without Blocking.
- // Callers must provide a preallocated FileDescriptorWatcher object which
- // can later be used to manage the Lifetime of this event.
+ // Have the current thread's message loop watch for a ready socket.
+ // Caller must provide a struct event for this socket for libevent's use.
+ // The event and interest_mask fields are defined in libevent.
// Returns true on success.
+ // TODO(dkegel): hide libevent better; abstraction still too leaky
+ // TODO(dkegel): better error handing
// TODO(dkegel): switch to edge-triggered readiness notification
- bool WatchFileDescriptor(int fd,
- bool persistent,
- Mode mode,
- FileDescriptorWatcher *controller,
- Watcher *delegate);
+ void WatchSocket(int socket, short interest_mask, event* e, Watcher*);
+ // TODO(playmobil): Merge this with WatchSocket().
+ void WatchFileHandle(int fd, short interest_mask, event* e, FileWatcher*);
+
+ // Stop watching a socket.
+ // Event was previously initialized by WatchSocket.
+ void UnwatchSocket(event* e);
+
+ // Stop watching a File Handle.
+ // Event was previously initialized by WatchFileHandle.
+ void UnwatchFileHandle(event* e);
+
// MessagePump methods:
virtual void Run(Delegate* delegate);
virtual void Quit();
@@ -103,10 +83,15 @@
// readiness callbacks when a socket is ready for I/O.
event_base* event_base_;
- // Called by libevent to tell us a registered FD can be read/written to.
- static void OnLibeventNotification(int fd, short flags,
- void* context);
+ // Called by libevent to tell us a registered socket is ready
+ static void OnReadinessNotification(int socket, short flags, void* context);
+ // Called by libevent to tell us a registered fd is ready.
+ static void OnFileReadReadinessNotification(int fd, short flags,
+ void* context);
+ static void OnFileWriteReadinessNotification(int fd, short flags,
+ void* context);
+
// Unix pipe used to implement ScheduleWork()
// ... callback; called by libevent inside Run() when pipe is ready to read
static void OnWakeup(int socket, short flags, void* context);
« no previous file with comments | « base/message_loop.cc ('k') | base/message_pump_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698