OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/system/raw_channel.h" | 5 #include "mojo/system/raw_channel.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 | 364 |
365 RawChannel::IOResult RawChannelWin::Read(size_t* bytes_read) { | 365 RawChannel::IOResult RawChannelWin::Read(size_t* bytes_read) { |
366 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); | 366 DCHECK_EQ(base::MessageLoop::current(), message_loop_for_io()); |
367 DCHECK(io_handler_); | 367 DCHECK(io_handler_); |
368 DCHECK(!io_handler_->pending_read()); | 368 DCHECK(!io_handler_->pending_read()); |
369 | 369 |
370 char* buffer = nullptr; | 370 char* buffer = nullptr; |
371 size_t bytes_to_read = 0; | 371 size_t bytes_to_read = 0; |
372 read_buffer()->GetBuffer(&buffer, &bytes_to_read); | 372 read_buffer()->GetBuffer(&buffer, &bytes_to_read); |
373 | 373 |
374 DWORD bytes_read_dword = 0; | |
375 BOOL result = ReadFile(io_handler_->handle(), | 374 BOOL result = ReadFile(io_handler_->handle(), |
376 buffer, | 375 buffer, |
377 static_cast<DWORD>(bytes_to_read), | 376 static_cast<DWORD>(bytes_to_read), |
378 &bytes_read_dword, | 377 NULL, |
viettrungluu
2014/09/30 19:07:40
nullptr
| |
379 &io_handler_->read_context()->overlapped); | 378 &io_handler_->read_context()->overlapped); |
380 if (!result) { | 379 if (!result) { |
381 DCHECK_EQ(bytes_read_dword, 0u); | |
382 DWORD error = GetLastError(); | 380 DWORD error = GetLastError(); |
383 if (error == ERROR_BROKEN_PIPE) | 381 if (error == ERROR_BROKEN_PIPE) |
384 return IO_FAILED_SHUTDOWN; | 382 return IO_FAILED_SHUTDOWN; |
385 if (error != ERROR_IO_PENDING) { | 383 if (error != ERROR_IO_PENDING) { |
386 LOG(WARNING) << "ReadFile: " << logging::SystemErrorCodeToString(error); | 384 LOG(WARNING) << "ReadFile: " << logging::SystemErrorCodeToString(error); |
387 return IO_FAILED_UNKNOWN; | 385 return IO_FAILED_UNKNOWN; |
388 } | 386 } |
389 } | 387 } |
390 | 388 |
391 if (result && skip_completion_port_on_success_) { | 389 if (result && skip_completion_port_on_success_) { |
390 DWORD bytes_read_dword = 0; | |
391 BOOL get_size_result = | |
392 GetOverlappedResult(io_handler_->handle(), | |
393 &io_handler_->read_context()->overlapped, | |
394 &bytes_read_dword, | |
395 FALSE); | |
396 DPCHECK(get_size_result); | |
392 *bytes_read = bytes_read_dword; | 397 *bytes_read = bytes_read_dword; |
393 return IO_SUCCEEDED; | 398 return IO_SUCCEEDED; |
394 } | 399 } |
395 | 400 |
396 // If the read is pending or the read has succeeded but we don't skip | 401 // If the read is pending or the read has succeeded but we don't skip |
397 // completion port on success, instruct |io_handler_| to wait for the | 402 // completion port on success, instruct |io_handler_| to wait for the |
398 // completion packet. | 403 // completion packet. |
399 // | 404 // |
400 // TODO(yzshen): It seems there isn't document saying that all error cases | 405 // TODO(yzshen): It seems there isn't document saying that all error cases |
401 // (other than ERROR_IO_PENDING) are guaranteed to *not* queue a completion | 406 // (other than ERROR_IO_PENDING) are guaranteed to *not* queue a completion |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 | 576 |
572 // Static factory method declared in raw_channel.h. | 577 // Static factory method declared in raw_channel.h. |
573 // static | 578 // static |
574 scoped_ptr<RawChannel> RawChannel::Create( | 579 scoped_ptr<RawChannel> RawChannel::Create( |
575 embedder::ScopedPlatformHandle handle) { | 580 embedder::ScopedPlatformHandle handle) { |
576 return make_scoped_ptr(new RawChannelWin(handle.Pass())); | 581 return make_scoped_ptr(new RawChannelWin(handle.Pass())); |
577 } | 582 } |
578 | 583 |
579 } // namespace system | 584 } // namespace system |
580 } // namespace mojo | 585 } // namespace mojo |
OLD | NEW |