OLD | NEW |
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 DCHECK_EQ(num_bytes_written % element_num_bytes(), 0u); | 137 DCHECK_EQ(num_bytes_written % element_num_bytes(), 0u); |
138 current_num_bytes_ += num_bytes_written; | 138 current_num_bytes_ += num_bytes_written; |
139 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); | 139 DCHECK_LE(current_num_bytes_, capacity_num_bytes()); |
140 set_producer_two_phase_max_num_bytes_written(0); | 140 set_producer_two_phase_max_num_bytes_written(0); |
141 return MOJO_RESULT_OK; | 141 return MOJO_RESULT_OK; |
142 } | 142 } |
143 | 143 |
144 HandleSignalsState LocalDataPipeImpl::ProducerGetHandleSignalsState() const { | 144 HandleSignalsState LocalDataPipeImpl::ProducerGetHandleSignalsState() const { |
145 HandleSignalsState rv; | 145 HandleSignalsState rv; |
146 if (consumer_open()) { | 146 if (consumer_open()) { |
147 if (current_num_bytes_ < capacity_num_bytes() && | 147 if (!producer_in_two_phase_write()) { |
148 !producer_in_two_phase_write()) | 148 // |producer_write_threshold_num_bytes()| is always at least 1. |
149 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; | 149 if (capacity_num_bytes() - current_num_bytes_ >= |
150 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; | 150 producer_write_threshold_num_bytes()) { |
| 151 rv.satisfied_signals |= |
| 152 MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_WRITE_THRESHOLD; |
| 153 } else if (current_num_bytes_ < capacity_num_bytes()) { |
| 154 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_WRITABLE; |
| 155 } |
| 156 } |
| 157 rv.satisfiable_signals |= |
| 158 MOJO_HANDLE_SIGNAL_WRITABLE | MOJO_HANDLE_SIGNAL_WRITE_THRESHOLD; |
151 } else { | 159 } else { |
152 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 160 rv.satisfied_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
153 } | 161 } |
154 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; | 162 rv.satisfiable_signals |= MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
155 return rv; | 163 return rv; |
156 } | 164 } |
157 | 165 |
158 void LocalDataPipeImpl::ProducerStartSerialize(Channel* channel, | 166 void LocalDataPipeImpl::ProducerStartSerialize(Channel* channel, |
159 size_t* max_size, | 167 size_t* max_size, |
160 size_t* max_platform_handles) { | 168 size_t* max_platform_handles) { |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 | 452 |
445 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { | 453 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { |
446 DCHECK_LE(num_bytes, current_num_bytes_); | 454 DCHECK_LE(num_bytes, current_num_bytes_); |
447 start_index_ += num_bytes; | 455 start_index_ += num_bytes; |
448 start_index_ %= capacity_num_bytes(); | 456 start_index_ %= capacity_num_bytes(); |
449 current_num_bytes_ -= num_bytes; | 457 current_num_bytes_ -= num_bytes; |
450 } | 458 } |
451 | 459 |
452 } // namespace system | 460 } // namespace system |
453 } // namespace mojo | 461 } // namespace mojo |
OLD | NEW |