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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 Channel::Message::Message(size_t payload_size, size_t num_handles) { | 30 Channel::Message::Message(size_t payload_size, size_t num_handles) { |
31 size_ = payload_size + sizeof(Header); | 31 size_ = payload_size + sizeof(Header); |
32 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
33 // On Windows we serialize platform handles directly into the message buffer. | 33 // On Windows we serialize platform handles directly into the message buffer. |
34 size_ += num_handles * sizeof(PlatformHandle); | 34 size_ += num_handles * sizeof(PlatformHandle); |
35 #endif | 35 #endif |
36 | 36 |
37 data_ = static_cast<char*>(base::AlignedAlloc(size_, | 37 data_ = static_cast<char*>(base::AlignedAlloc(size_, |
38 kChannelMessageAlignment)); | 38 kChannelMessageAlignment)); |
39 memset(data_, 0, size_); | |
40 header_ = reinterpret_cast<Header*>(data_); | 39 header_ = reinterpret_cast<Header*>(data_); |
41 | 40 |
42 DCHECK_LE(size_, std::numeric_limits<uint32_t>::max()); | 41 DCHECK_LE(size_, std::numeric_limits<uint32_t>::max()); |
43 header_->num_bytes = static_cast<uint32_t>(size_); | 42 header_->num_bytes = static_cast<uint32_t>(size_); |
44 | 43 |
45 DCHECK_LE(num_handles, std::numeric_limits<uint16_t>::max()); | 44 DCHECK_LE(num_handles, std::numeric_limits<uint16_t>::max()); |
46 header_->num_handles = static_cast<uint16_t>(num_handles); | 45 header_->num_handles = static_cast<uint16_t>(num_handles); |
47 | 46 |
48 header_->padding = 0; | 47 header_->padding = 0; |
49 | 48 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 return true; | 330 return true; |
332 } | 331 } |
333 | 332 |
334 void Channel::OnError() { | 333 void Channel::OnError() { |
335 if (delegate_) | 334 if (delegate_) |
336 delegate_->OnChannelError(); | 335 delegate_->OnChannelError(); |
337 } | 336 } |
338 | 337 |
339 } // namespace edk | 338 } // namespace edk |
340 } // namespace mojo | 339 } // namespace mojo |
OLD | NEW |