| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_channel_win.h" | 5 #include "ipc/ipc_channel_win.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 : ChannelReader(listener), | 59 : ChannelReader(listener), |
| 60 input_state_(this), | 60 input_state_(this), |
| 61 output_state_(this), | 61 output_state_(this), |
| 62 pipe_(INVALID_HANDLE_VALUE), | 62 pipe_(INVALID_HANDLE_VALUE), |
| 63 peer_pid_(base::kNullProcessId), | 63 peer_pid_(base::kNullProcessId), |
| 64 waiting_connect_(mode & MODE_SERVER_FLAG), | 64 waiting_connect_(mode & MODE_SERVER_FLAG), |
| 65 processing_incoming_(false), | 65 processing_incoming_(false), |
| 66 validate_client_(false), | 66 validate_client_(false), |
| 67 writing_(false), | 67 writing_(false), |
| 68 debug_flags_(0), | 68 debug_flags_(0), |
| 69 write_error_(0), |
| 70 last_write_error_(0), |
| 71 write_size_(0), |
| 69 client_secret_(0), | 72 client_secret_(0), |
| 70 weak_factory_(this) { | 73 weak_factory_(this) { |
| 71 CreatePipe(channel_handle, mode); | 74 CreatePipe(channel_handle, mode); |
| 72 } | 75 } |
| 73 | 76 |
| 74 ChannelWin::~ChannelWin() { | 77 ChannelWin::~ChannelWin() { |
| 75 Close(); | 78 Close(); |
| 76 } | 79 } |
| 77 | 80 |
| 78 void ChannelWin::Close() { | 81 void ChannelWin::Close() { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 435 |
| 433 if (INVALID_HANDLE_VALUE == pipe_) | 436 if (INVALID_HANDLE_VALUE == pipe_) |
| 434 return false; | 437 return false; |
| 435 | 438 |
| 436 // Write to pipe... | 439 // Write to pipe... |
| 437 Message* m = output_queue_.front(); | 440 Message* m = output_queue_.front(); |
| 438 DCHECK(m->size() <= INT_MAX); | 441 DCHECK(m->size() <= INT_MAX); |
| 439 debug_flags_ |= WRITE_MSG; | 442 debug_flags_ |= WRITE_MSG; |
| 440 CHECK(!writing_); | 443 CHECK(!writing_); |
| 441 writing_ = true; | 444 writing_ = true; |
| 445 write_size_ = static_cast<uint32>(m->size()); |
| 446 write_error_ = 0; |
| 442 BOOL ok = WriteFile(pipe_, | 447 BOOL ok = WriteFile(pipe_, |
| 443 m->data(), | 448 m->data(), |
| 444 static_cast<int>(m->size()), | 449 write_size_, |
| 445 &bytes_written, | 450 NULL, |
| 446 &output_state_.context.overlapped); | 451 &output_state_.context.overlapped); |
| 447 if (!ok) { | 452 if (!ok) { |
| 448 DWORD err = GetLastError(); | 453 write_error_ = GetLastError(); |
| 449 if (err == ERROR_IO_PENDING) { | 454 if (write_error_ == ERROR_IO_PENDING) { |
| 450 output_state_.is_pending = true; | 455 output_state_.is_pending = true; |
| 451 | 456 |
| 452 DVLOG(2) << "sent pending message @" << m << " on channel @" << this | 457 DVLOG(2) << "sent pending message @" << m << " on channel @" << this |
| 453 << " with type " << m->type(); | 458 << " with type " << m->type(); |
| 454 | 459 |
| 455 return true; | 460 return true; |
| 456 } | 461 } |
| 457 writing_ = false; | 462 writing_ = false; |
| 458 LOG(ERROR) << "pipe error: " << err; | 463 last_write_error_ = write_error_; |
| 464 LOG(ERROR) << "pipe error: " << write_error_; |
| 459 return false; | 465 return false; |
| 460 } | 466 } |
| 461 | 467 |
| 462 DVLOG(2) << "sent message @" << m << " on channel @" << this | 468 DVLOG(2) << "sent message @" << m << " on channel @" << this |
| 463 << " with type " << m->type(); | 469 << " with type " << m->type(); |
| 464 | 470 |
| 465 output_state_.is_pending = true; | 471 output_state_.is_pending = true; |
| 466 return true; | 472 return true; |
| 467 } | 473 } |
| 468 | 474 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 int secret; | 564 int secret; |
| 559 do { // Guarantee we get a non-zero value. | 565 do { // Guarantee we get a non-zero value. |
| 560 secret = base::RandInt(0, std::numeric_limits<int>::max()); | 566 secret = base::RandInt(0, std::numeric_limits<int>::max()); |
| 561 } while (secret == 0); | 567 } while (secret == 0); |
| 562 | 568 |
| 563 id.append(GenerateUniqueRandomChannelID()); | 569 id.append(GenerateUniqueRandomChannelID()); |
| 564 return id.append(base::StringPrintf("\\%d", secret)); | 570 return id.append(base::StringPrintf("\\%d", secret)); |
| 565 } | 571 } |
| 566 | 572 |
| 567 } // namespace IPC | 573 } // namespace IPC |
| OLD | NEW |