diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-10 22:00:08 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-10 22:00:08 +0000 |
commit | 88871375bfbae5ba4811866c2daccc78e282bbef (patch) | |
tree | eeda3b32a3b800c1f6699fe39a26b24713966032 /net | |
parent | d074bcc717295e16e2fc48edd7ec5a4641f7cc39 (diff) | |
download | chromium_src-88871375bfbae5ba4811866c2daccc78e282bbef.zip chromium_src-88871375bfbae5ba4811866c2daccc78e282bbef.tar.gz chromium_src-88871375bfbae5ba4811866c2daccc78e282bbef.tar.bz2 |
Remove WatchObject calls from FileInputStream.
Review URL: http://codereview.chromium.org/6030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/file_input_stream_win.cc | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/net/base/file_input_stream_win.cc b/net/base/file_input_stream_win.cc index 5eadc9d..f964362 100644 --- a/net/base/file_input_stream_win.cc +++ b/net/base/file_input_stream_win.cc @@ -47,7 +47,7 @@ static int MapErrorCode(DWORD err) { // FileInputStream::AsyncContext ---------------------------------------------- -class FileInputStream::AsyncContext : public MessageLoopForIO::Watcher { +class FileInputStream::AsyncContext : public MessageLoopForIO::IOHandler { public: AsyncContext(FileInputStream* owner) : owner_(owner), overlapped_(), callback_(NULL) { @@ -56,7 +56,7 @@ class FileInputStream::AsyncContext : public MessageLoopForIO::Watcher { ~AsyncContext() { if (callback_) - MessageLoopForIO::current()->WatchObject(overlapped_.hEvent, NULL); + MessageLoopForIO::current()->RegisterIOContext(&overlapped_, NULL); CloseHandle(overlapped_.hEvent); } @@ -66,8 +66,9 @@ class FileInputStream::AsyncContext : public MessageLoopForIO::Watcher { CompletionCallback* callback() const { return callback_; } private: - // MessageLoopForIO::Watcher implementation: - virtual void OnObjectSignaled(HANDLE object); + // MessageLoopForIO::IOHandler implementation: + virtual void OnIOCompleted(OVERLAPPED* context, DWORD bytes_read, + DWORD error); FileInputStream* owner_; OVERLAPPED overlapped_; @@ -79,31 +80,25 @@ void FileInputStream::AsyncContext::IOCompletionIsPending( DCHECK(!callback_); callback_ = callback; - MessageLoopForIO::current()->WatchObject(overlapped_.hEvent, this); + MessageLoopForIO::current()->RegisterIOContext(&overlapped_, this); } -void FileInputStream::AsyncContext::OnObjectSignaled(HANDLE object) { - DCHECK(overlapped_.hEvent == object); +void FileInputStream::AsyncContext::OnIOCompleted(OVERLAPPED* context, + DWORD bytes_read, + DWORD error) { + DCHECK(&overlapped_ == context); DCHECK(callback_); - MessageLoopForIO::current()->WatchObject(overlapped_.hEvent, NULL); + MessageLoopForIO::current()->RegisterIOContext(&overlapped_, NULL); HANDLE handle = owner_->handle_; - int result; - - DWORD bytes_read; - if (!GetOverlappedResult(handle, &overlapped_, &bytes_read, FALSE)) { - DWORD err = GetLastError(); - if (err == ERROR_HANDLE_EOF) { - result = OK; // Successfully read all data. - } else { - result = MapErrorCode(err); - } - } else { + int result = static_cast<int>(bytes_read); + if (error && error != ERROR_HANDLE_EOF) + result = MapErrorCode(error); + + if (bytes_read) IncrementOffset(&overlapped_, bytes_read); - result = static_cast<int>(bytes_read); - } CompletionCallback* temp = NULL; std::swap(temp, callback_); @@ -150,8 +145,11 @@ int FileInputStream::Open(const std::wstring& path, bool asynchronous_mode) { return MapErrorCode(error); } - if (asynchronous_mode) + if (asynchronous_mode) { async_context_.reset(new AsyncContext(this)); + MessageLoopForIO::current()->RegisterIOHandler(handle_, + async_context_.get()); + } return OK; } |