diff options
author | ojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 19:55:17 +0000 |
---|---|---|
committer | ojan@google.com <ojan@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-12 19:55:17 +0000 |
commit | 900342a3e34354312a2ce854196e95fa8a0c07c4 (patch) | |
tree | 8d73bce7518e4077c805053cb553ef11b3b1949d /base/message_pump_libevent.h | |
parent | ab844167875b2003cb44081c6b64c0097df30b48 (diff) | |
download | chromium_src-900342a3e34354312a2ce854196e95fa8a0c07c4.zip chromium_src-900342a3e34354312a2ce854196e95fa8a0c07c4.tar.gz chromium_src-900342a3e34354312a2ce854196e95fa8a0c07c4.tar.bz2 |
Reverting 6911.
Review URL: http://codereview.chromium.org/14068
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6916 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_libevent.h')
-rw-r--r-- | base/message_pump_libevent.h | 91 |
1 files changed, 38 insertions, 53 deletions
diff --git a/base/message_pump_libevent.h b/base/message_pump_libevent.h index 36475c1..b54bc36 100644 --- a/base/message_pump_libevent.h +++ b/base/message_pump_libevent.h @@ -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,65 +18,46 @@ namespace base { // 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); @@ -103,9 +83,14 @@ class MessagePumpLibevent : public MessagePump { // 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 |