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

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

Issue 1856113002: EDK: Add implementation of data pipe consumer read threshold stuff. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // TODO(vtl): I currently potentially overflow in doing index calculations. 5 // TODO(vtl): I currently potentially overflow in doing index calculations.
6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but 6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but
7 // their sum may not. This is bad and poses a security risk. (We're currently 7 // their sum may not. This is bad and poses a security risk. (We're currently
8 // saved by the limit on capacity -- the maximum size of the buffer, checked in 8 // saved by the limit on capacity -- the maximum size of the buffer, checked in
9 // |DataPipe::ValidateOptions()|, is currently sufficiently small.) 9 // |DataPipe::ValidateOptions()|, is currently sufficiently small.)
10 10
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read()); 307 DCHECK_LE(num_bytes_read, consumer_two_phase_max_num_bytes_read());
308 DCHECK_EQ(num_bytes_read % element_num_bytes(), 0u); 308 DCHECK_EQ(num_bytes_read % element_num_bytes(), 0u);
309 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); 309 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes());
310 MarkDataAsConsumed(num_bytes_read); 310 MarkDataAsConsumed(num_bytes_read);
311 set_consumer_two_phase_max_num_bytes_read(0); 311 set_consumer_two_phase_max_num_bytes_read(0);
312 return MOJO_RESULT_OK; 312 return MOJO_RESULT_OK;
313 } 313 }
314 314
315 HandleSignalsState LocalDataPipeImpl::ConsumerGetHandleSignalsState() const { 315 HandleSignalsState LocalDataPipeImpl::ConsumerGetHandleSignalsState() const {
316 HandleSignalsState rv; 316 HandleSignalsState rv;
317 if (current_num_bytes_ > 0) { 317 // |consumer_read_threshold_num_bytes()| is always at least 1.
318 if (current_num_bytes_ >= consumer_read_threshold_num_bytes()) {
319 if (!consumer_in_two_phase_read()) {
320 rv.satisfied_signals |=
321 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_READ_THRESHOLD;
322 }
323 rv.satisfiable_signals |=
324 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_READ_THRESHOLD;
325 } else if (current_num_bytes_ > 0u) {
318 if (!consumer_in_two_phase_read()) 326 if (!consumer_in_two_phase_read())
319 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; 327 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE;
320 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; 328 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE;
321 } else if (producer_open()) {
322 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE;
323 } 329 }
324 if (!producer_open()) 330 if (producer_open()) {
331 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE |
332 MOJO_HANDLE_SIGNAL_PEER_CLOSED |
333 MOJO_HANDLE_SIGNAL_READ_THRESHOLD;
334 } else {
325 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; 335 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED;
326 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; 336 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED;
337 }
327 return rv; 338 return rv;
328 } 339 }
329 340
330 void LocalDataPipeImpl::ConsumerStartSerialize(Channel* channel, 341 void LocalDataPipeImpl::ConsumerStartSerialize(Channel* channel,
331 size_t* max_size, 342 size_t* max_size,
332 size_t* max_platform_handles) { 343 size_t* max_platform_handles) {
333 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + 344 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) +
334 channel->GetSerializedEndpointSize(); 345 channel->GetSerializedEndpointSize();
335 *max_platform_handles = 0; 346 *max_platform_handles = 0;
336 } 347 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 444
434 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { 445 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) {
435 DCHECK_LE(num_bytes, current_num_bytes_); 446 DCHECK_LE(num_bytes, current_num_bytes_);
436 start_index_ += num_bytes; 447 start_index_ += num_bytes;
437 start_index_ %= capacity_num_bytes(); 448 start_index_ %= capacity_num_bytes();
438 current_num_bytes_ -= num_bytes; 449 current_num_bytes_ -= num_bytes;
439 } 450 }
440 451
441 } // namespace system 452 } // namespace system
442 } // namespace mojo 453 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/dispatcher_unittest.cc ('k') | mojo/edk/system/remote_data_pipe_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698