Chromium Code Reviews| 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 "chrome/nacl/nacl_ipc_adapter.h" | 5 #include "chrome/nacl/nacl_ipc_adapter.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 if (bytes_to_write == 0) | 253 if (bytes_to_write == 0) |
| 254 return 0; | 254 return 0; |
| 255 | 255 |
| 256 memcpy(dest_buffer, &data_[data_read_cursor_], bytes_to_write); | 256 memcpy(dest_buffer, &data_[data_read_cursor_], bytes_to_write); |
| 257 data_read_cursor_ += bytes_to_write; | 257 data_read_cursor_ += bytes_to_write; |
| 258 | 258 |
| 259 // Once all data has been consumed, transfer any file descriptors. | 259 // Once all data has been consumed, transfer any file descriptors. |
| 260 if (is_consumed()) { | 260 if (is_consumed()) { |
| 261 nacl_abi_size_t desc_count = static_cast<nacl_abi_size_t>(descs_.size()); | 261 nacl_abi_size_t desc_count = static_cast<nacl_abi_size_t>(descs_.size()); |
| 262 CHECK(desc_count <= msg->ndesc_length); | 262 CHECK(desc_count <= msg->ndesc_length); |
| 263 msg->ndesc_length = desc_count; | 263 msg->ndesc_length = desc_count; |
|
Mark Seaborn
2012/09/19 23:25:14
It's kind of odd that your new ndesc_length assign
bbudge
2012/09/19 23:46:09
Very odd.
| |
| 264 for (nacl_abi_size_t i = 0; i < desc_count; i++) { | 264 for (nacl_abi_size_t i = 0; i < desc_count; i++) { |
| 265 // Copy the NaClDesc to the buffer and add a ref so it won't be freed | 265 // Copy the NaClDesc to the buffer and add a ref so it won't be freed |
| 266 // when we clear our ScopedVector. | 266 // when we clear our ScopedVector. |
| 267 msg->ndescv[i] = descs_[i]->desc(); | 267 msg->ndescv[i] = descs_[i]->desc(); |
| 268 NaClDescRef(descs_[i]->desc()); | 268 NaClDescRef(descs_[i]->desc()); |
| 269 } | 269 } |
| 270 descs_.clear(); | 270 descs_.clear(); |
| 271 } | 271 } |
|
Mark Seaborn
2012/09/19 23:25:14
...is there a reason you don't do the following he
bbudge
2012/09/19 23:46:09
You're right, this is a much better place. Done.
| |
| 272 return static_cast<int>(bytes_to_write); | 272 return static_cast<int>(bytes_to_write); |
| 273 } | 273 } |
| 274 | 274 |
| 275 NaClIPCAdapter::LockedData::LockedData() | 275 NaClIPCAdapter::LockedData::LockedData() |
| 276 : channel_closed_(false) { | 276 : channel_closed_(false) { |
| 277 } | 277 } |
| 278 | 278 |
| 279 NaClIPCAdapter::LockedData::~LockedData() { | 279 NaClIPCAdapter::LockedData::~LockedData() { |
| 280 } | 280 } |
| 281 | 281 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 573 if (locked_data_.to_be_received_.empty()) | 573 if (locked_data_.to_be_received_.empty()) |
| 574 return 0; | 574 return 0; |
| 575 scoped_refptr<RewrittenMessage> current = | 575 scoped_refptr<RewrittenMessage> current = |
| 576 locked_data_.to_be_received_.front(); | 576 locked_data_.to_be_received_.front(); |
| 577 | 577 |
| 578 int retval = current->Read(msg); | 578 int retval = current->Read(msg); |
| 579 | 579 |
| 580 // When a message is entirely consumed, remove if from the waiting queue. | 580 // When a message is entirely consumed, remove if from the waiting queue. |
| 581 if (current->is_consumed()) | 581 if (current->is_consumed()) |
| 582 locked_data_.to_be_received_.pop(); | 582 locked_data_.to_be_received_.pop(); |
| 583 else | |
| 584 msg->ndesc_length = 0; | |
|
dmichael (off chromium)
2012/09/19 22:47:48
Would it be good to either add a comment or move t
bbudge
2012/09/19 23:46:09
Done.
Mark Seaborn
2012/09/20 00:28:42
Did you mean to re-upload? I just see the origina
| |
| 583 | 585 |
| 584 return retval; | 586 return retval; |
| 585 } | 587 } |
| 586 | 588 |
| 587 bool NaClIPCAdapter::SendCompleteMessage(const char* buffer, | 589 bool NaClIPCAdapter::SendCompleteMessage(const char* buffer, |
| 588 size_t buffer_len) { | 590 size_t buffer_len) { |
| 589 // The message will have already been validated, so we know it's large enough | 591 // The message will have already been validated, so we know it's large enough |
| 590 // for our header. | 592 // for our header. |
| 591 const NaClMessageHeader* header = | 593 const NaClMessageHeader* header = |
| 592 reinterpret_cast<const NaClMessageHeader*>(buffer); | 594 reinterpret_cast<const NaClMessageHeader*>(buffer); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 668 header.payload_size = static_cast<uint32>(msg.payload_size()); | 670 header.payload_size = static_cast<uint32>(msg.payload_size()); |
| 669 header.routing = msg.routing_id(); | 671 header.routing = msg.routing_id(); |
| 670 header.type = msg.type(); | 672 header.type = msg.type(); |
| 671 header.flags = msg.flags(); | 673 header.flags = msg.flags(); |
| 672 header.num_fds = static_cast<int>(rewritten_msg->desc_count()); | 674 header.num_fds = static_cast<int>(rewritten_msg->desc_count()); |
| 673 | 675 |
| 674 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); | 676 rewritten_msg->SetData(header, msg.payload(), msg.payload_size()); |
| 675 locked_data_.to_be_received_.push(rewritten_msg); | 677 locked_data_.to_be_received_.push(rewritten_msg); |
| 676 } | 678 } |
| 677 | 679 |
| OLD | NEW |