Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1611)

Side by Side Diff: mojo/edk/system/data_pipe_impl.cc

Issue 973513004: Allow data pipe producer/consumer handles to be re-sent. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: review comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/system/data_pipe_impl.h ('k') | mojo/edk/system/data_pipe_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/edk/system/data_pipe_impl.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "mojo/edk/system/configuration.h"
12 #include "mojo/edk/system/message_in_transit.h"
13 #include "mojo/edk/system/message_in_transit_queue.h"
14
15 namespace mojo {
16 namespace system {
17
18 void DataPipeImpl::ConvertDataToMessages(const char* buffer,
19 size_t* start_index,
20 size_t* current_num_bytes,
21 MessageInTransitQueue* message_queue) {
22 // The maximum amount of data to send per message (make it a multiple of the
23 // element size.
24 size_t max_message_num_bytes = GetConfiguration().max_message_num_bytes;
25 max_message_num_bytes -= max_message_num_bytes % element_num_bytes();
26 DCHECK_GT(max_message_num_bytes, 0u);
27
28 while (*current_num_bytes > 0) {
29 size_t current_contiguous_num_bytes =
30 (*start_index + *current_num_bytes > capacity_num_bytes())
31 ? (capacity_num_bytes() - *start_index)
32 : *current_num_bytes;
33 size_t message_num_bytes =
34 std::min(max_message_num_bytes, current_contiguous_num_bytes);
35
36 // Note: |message_num_bytes| fits in a |uint32_t| since the capacity does.
37 scoped_ptr<MessageInTransit> message(new MessageInTransit(
38 MessageInTransit::kTypeEndpoint, MessageInTransit::kSubtypeEndpointData,
39 static_cast<uint32_t>(message_num_bytes), buffer + *start_index));
40 message_queue->AddMessage(message.Pass());
41
42 DCHECK_LE(message_num_bytes, *current_num_bytes);
43 *start_index += message_num_bytes;
44 *start_index %= capacity_num_bytes();
45 *current_num_bytes -= message_num_bytes;
46 }
47 }
48
49 } // namespace system
50 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/data_pipe_impl.h ('k') | mojo/edk/system/data_pipe_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698