summaryrefslogtreecommitdiffstats
path: root/base/message_pump_win.h
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-09 23:58:43 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-09 23:58:43 +0000
commit32cda29d0266751c764b043d8aaec6dccc646e29 (patch)
treef7a4b556c69da92949236cb8eb9a5e4647147099 /base/message_pump_win.h
parentdd59411d090b2a6a7327f5c0d527321bdccd5e84 (diff)
downloadchromium_src-32cda29d0266751c764b043d8aaec6dccc646e29.zip
chromium_src-32cda29d0266751c764b043d8aaec6dccc646e29.tar.gz
chromium_src-32cda29d0266751c764b043d8aaec6dccc646e29.tar.bz2
Add a way to register for completion-ports based async operations to be handled
through the windows version of the message pump. As a first step, actual IO processing is still performed using WatchObject instead of using completion ports. Review URL: http://codereview.chromium.org/1950 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3157 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_win.h')
-rw-r--r--base/message_pump_win.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/base/message_pump_win.h b/base/message_pump_win.h
index 0192e3c..50a5223 100644
--- a/base/message_pump_win.h
+++ b/base/message_pump_win.h
@@ -12,6 +12,7 @@
#include "base/lock.h"
#include "base/message_pump.h"
#include "base/observer_list.h"
+#include "base/scoped_handle.h"
#include "base/time.h"
namespace base {
@@ -193,6 +194,20 @@ class MessagePumpForIO : public MessagePumpWin {
virtual void OnObjectSignaled(HANDLE object) = 0;
};
+ // Clients interested in receiving OS notifications when asynchronous IO
+ // operations complete should implement this interface and register themselves
+ // with the message pump.
+ class IOHandler {
+ public:
+ virtual ~IOHandler() {}
+ // This will be called once the pending IO operation associated with
+ // |context| completes. |error| is the Win32 error code of the IO operation
+ // (ERROR_SUCCESS if there was no error). |bytes_transfered| will be zero
+ // on error.
+ virtual void OnIOCompleted(OVERLAPPED* context, DWORD bytes_transfered,
+ DWORD error) = 0;
+ };
+
MessagePumpForIO() {}
virtual ~MessagePumpForIO() {}
@@ -200,6 +215,22 @@ class MessagePumpForIO : public MessagePumpWin {
// Pass a null watcher to stop watching the object.
void WatchObject(HANDLE, Watcher*);
+ // Register the handler to be used when asynchronous IO for the given file
+ // completes. The registration persists as long as |file_handle| is valid, so
+ // |handler| must be valid as long as there is pending IO for the given file.
+ void RegisterIOHandler(HANDLE file_handle, IOHandler* handler);
+
+ // This is just a throw away function to ease transition to completion ports.
+ // Pass NULL for handler to stop tracking this request. WARNING: cancellation
+ // correctness is the responsibility of the caller. |context| must contain a
+ // valid manual reset event, but the caller should not interact directly with
+ // it. The registration can live across a single IO operation, or it can live
+ // across multiple IO operations without having to reset it after each IO
+ // completion callback. Internally, there will be a WatchObject registration
+ // alive as long as this context registration is in effect. It is an error
+ // to unregister a context that has not been registered before.
+ void RegisterIOContext(OVERLAPPED* context, IOHandler* handler);
+
private:
virtual void DoRunLoop();
void WaitForWork();
@@ -210,6 +241,9 @@ class MessagePumpForIO : public MessagePumpWin {
// serviced by this message pump.
std::vector<HANDLE> objects_;
std::vector<Watcher*> watchers_;
+
+ // The completion port associated with this thread.
+ ScopedHandle port_;
};
} // namespace base