Chromium Code Reviews| Index: mojo/edk/system/channel_win.cc |
| diff --git a/mojo/edk/system/channel_win.cc b/mojo/edk/system/channel_win.cc |
| index d04edaf580a92a1c1f7ec10a8befcbb5eb0763b3..bc96a5ffc69466cd820231963baaadb1bfd010b1 100644 |
| --- a/mojo/edk/system/channel_win.cc |
| +++ b/mojo/edk/system/channel_win.cc |
| @@ -85,6 +85,8 @@ class ChannelWin : public Channel, |
| memset(&write_context_, 0, sizeof(write_context_)); |
| write_context_.handler = this; |
| + |
| + wait_for_connect_ = handle_.get().needs_connection; |
| } |
| void Start() override { |
| @@ -148,6 +150,29 @@ class ChannelWin : public Channel, |
| base::MessageLoopForIO::current()->RegisterIOHandler( |
| handle_.get().handle, this); |
| + if (wait_for_connect_) { |
| + BOOL ok = ConnectNamedPipe(handle_.get().handle, |
| + &read_context_.overlapped); |
|
Ken Rockot(use gerrit already)
2016/05/10 22:41:28
I'd rather we use a separate IO context for connec
Anand Mistry (off Chromium)
2016/05/11 04:15:20
Done.
|
| + if (ok) { |
| + PLOG(ERROR) << "Unexpected success while waiting for pipe connection"; |
| + OnError(); |
| + return; |
| + } |
| + |
| + const DWORD err = GetLastError(); |
| + switch (err) { |
| + case ERROR_PIPE_CONNECTED: |
| + wait_for_connect_ = false; |
| + break; |
| + case ERROR_IO_PENDING: |
| + AddRef(); |
| + return; |
| + case ERROR_NO_DATA: |
| + OnError(); |
| + return; |
| + } |
| + } |
| + |
| // Now that we have registered our IOHandler, we can start writing. |
| { |
| base::AutoLock lock(write_lock_); |
| @@ -191,7 +216,18 @@ class ChannelWin : public Channel, |
| if (error != ERROR_SUCCESS) { |
| OnError(); |
| } else if (context == &read_context_) { |
| - OnReadDone(static_cast<size_t>(bytes_transfered)); |
| + if (wait_for_connect_) { |
| + wait_for_connect_ = false; |
| + ReadMore(0); |
| + |
| + base::AutoLock lock(write_lock_); |
| + if (delay_writes_) { |
| + delay_writes_ = false; |
| + WriteNextNoLock(); |
| + } |
| + } else { |
| + OnReadDone(static_cast<size_t>(bytes_transfered)); |
| + } |
| } else { |
| CHECK(context == &write_context_); |
| OnWriteDone(static_cast<size_t>(bytes_transfered)); |
| @@ -309,6 +345,8 @@ class ChannelWin : public Channel, |
| // TODO(amistry): Remove before M50 branch point. |
| uintptr_t sentinel_; |
| + bool wait_for_connect_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ChannelWin); |
| }; |