| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/edk/system/channel.h" | 5 #include "mojo/edk/system/channel.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 if (write_error) { | 114 if (write_error) { |
| 115 // Do not synchronously invoke OnError(). Write() may have been called by | 115 // Do not synchronously invoke OnError(). Write() may have been called by |
| 116 // the delegate and we don't want to re-enter it. | 116 // the delegate and we don't want to re-enter it. |
| 117 io_task_runner_->PostTask(FROM_HERE, | 117 io_task_runner_->PostTask(FROM_HERE, |
| 118 base::Bind(&ChannelWin::OnError, this)); | 118 base::Bind(&ChannelWin::OnError, this)); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 ScopedPlatformHandleVectorPtr GetReadPlatformHandles( | 122 ScopedPlatformHandleVectorPtr GetReadPlatformHandles( |
| 123 size_t num_handles, | 123 size_t num_handles, |
| 124 void** payload, | 124 const void* extra_header, |
| 125 size_t* payload_size) override { | 125 size_t extra_header_size) override { |
| 126 size_t handles_size = sizeof(PlatformHandle) * num_handles; | 126 size_t handles_size = sizeof(PlatformHandle) * num_handles; |
| 127 if (handles_size > *payload_size) | 127 if (handles_size > extra_header_size) |
| 128 return nullptr; | 128 return nullptr; |
| 129 | 129 |
| 130 *payload_size -= handles_size; | |
| 131 ScopedPlatformHandleVectorPtr handles( | 130 ScopedPlatformHandleVectorPtr handles( |
| 132 new PlatformHandleVector(num_handles)); | 131 new PlatformHandleVector(num_handles)); |
| 133 memcpy(handles->data(), | 132 memcpy(handles->data(), extra_header, handles_size); |
| 134 static_cast<const char*>(*payload) + *payload_size, handles_size); | |
| 135 return handles; | 133 return handles; |
| 136 } | 134 } |
| 137 | 135 |
| 138 private: | 136 private: |
| 139 // May run on any thread. | 137 // May run on any thread. |
| 140 ~ChannelWin() override { | 138 ~ChannelWin() override { |
| 141 // This is intentionally not 0. If another object is constructed on top of | 139 // This is intentionally not 0. If another object is constructed on top of |
| 142 // this memory, it is likely to initialise values to 0. Using a non-zero | 140 // this memory, it is likely to initialise values to 0. Using a non-zero |
| 143 // value lets us detect the difference between just destroying, and | 141 // value lets us detect the difference between just destroying, and |
| 144 // re-allocating the memory. | 142 // re-allocating the memory. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // static | 317 // static |
| 320 scoped_refptr<Channel> Channel::Create( | 318 scoped_refptr<Channel> Channel::Create( |
| 321 Delegate* delegate, | 319 Delegate* delegate, |
| 322 ScopedPlatformHandle platform_handle, | 320 ScopedPlatformHandle platform_handle, |
| 323 scoped_refptr<base::TaskRunner> io_task_runner) { | 321 scoped_refptr<base::TaskRunner> io_task_runner) { |
| 324 return new ChannelWin(delegate, std::move(platform_handle), io_task_runner); | 322 return new ChannelWin(delegate, std::move(platform_handle), io_task_runner); |
| 325 } | 323 } |
| 326 | 324 |
| 327 } // namespace edk | 325 } // namespace edk |
| 328 } // namespace mojo | 326 } // namespace mojo |
| OLD | NEW |