| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/remote_producer_data_pipe_impl.h" | 5 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 DCHECK_EQ(num_bytes_read % element_num_bytes(), 0u); | 274 DCHECK_EQ(num_bytes_read % element_num_bytes(), 0u); |
| 275 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); | 275 DCHECK_LE(start_index_ + num_bytes_read, capacity_num_bytes()); |
| 276 MarkDataAsConsumed(num_bytes_read); | 276 MarkDataAsConsumed(num_bytes_read); |
| 277 set_consumer_two_phase_max_num_bytes_read(0); | 277 set_consumer_two_phase_max_num_bytes_read(0); |
| 278 return MOJO_RESULT_OK; | 278 return MOJO_RESULT_OK; |
| 279 } | 279 } |
| 280 | 280 |
| 281 HandleSignalsState RemoteProducerDataPipeImpl::ConsumerGetHandleSignalsState() | 281 HandleSignalsState RemoteProducerDataPipeImpl::ConsumerGetHandleSignalsState() |
| 282 const { | 282 const { |
| 283 HandleSignalsState rv; | 283 HandleSignalsState rv; |
| 284 if (current_num_bytes_ > 0) { | 284 // |consumer_read_threshold_num_bytes()| is always at least 1. |
| 285 if (current_num_bytes_ >= consumer_read_threshold_num_bytes()) { |
| 286 if (!consumer_in_two_phase_read()) { |
| 287 rv.satisfied_signals |= |
| 288 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_READ_THRESHOLD; |
| 289 } |
| 290 rv.satisfiable_signals |= |
| 291 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_READ_THRESHOLD; |
| 292 } else if (current_num_bytes_ > 0u) { |
| 285 if (!consumer_in_two_phase_read()) | 293 if (!consumer_in_two_phase_read()) |
| 286 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 294 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 287 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | 295 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; |
| 288 } else if (producer_open()) { | |
| 289 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE; | |
| 290 } | 296 } |
| 291 if (!producer_open()) | 297 if (producer_open()) { |
| 298 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_READABLE | |
| 299 MOJO_HANDLE_SIGNAL_PEER_CLOSED | |
| 300 MOJO_HANDLE_SIGNAL_READ_THRESHOLD; |
| 301 } else { |
| 292 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 302 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 293 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 303 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 304 } |
| 294 return rv; | 305 return rv; |
| 295 } | 306 } |
| 296 | 307 |
| 297 void RemoteProducerDataPipeImpl::ConsumerStartSerialize( | 308 void RemoteProducerDataPipeImpl::ConsumerStartSerialize( |
| 298 Channel* channel, | 309 Channel* channel, |
| 299 size_t* max_size, | 310 size_t* max_size, |
| 300 size_t* max_platform_handles) { | 311 size_t* max_platform_handles) { |
| 301 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + | 312 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + |
| 302 channel->GetSerializedEndpointSize(); | 313 channel->GetSerializedEndpointSize(); |
| 303 *max_platform_handles = 0; | 314 *max_platform_handles = 0; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 // If the consumer is still open and we still have data, we have to keep the | 473 // If the consumer is still open and we still have data, we have to keep the |
| 463 // buffer around. Currently, we won't free it even if it empties later. (We | 474 // buffer around. Currently, we won't free it even if it empties later. (We |
| 464 // could do this -- requiring a check on every read -- but that seems to be | 475 // could do this -- requiring a check on every read -- but that seems to be |
| 465 // optimizing for the uncommon case.) | 476 // optimizing for the uncommon case.) |
| 466 if (!consumer_open() || !current_num_bytes_) | 477 if (!consumer_open() || !current_num_bytes_) |
| 467 DestroyBuffer(); | 478 DestroyBuffer(); |
| 468 } | 479 } |
| 469 | 480 |
| 470 } // namespace system | 481 } // namespace system |
| 471 } // namespace mojo | 482 } // namespace mojo |
| OLD | NEW |