| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 UserPointer<const void> /*elements*/, | 126 UserPointer<const void> /*elements*/, |
| 127 UserPointer<uint32_t> /*num_bytes*/, | 127 UserPointer<uint32_t> /*num_bytes*/, |
| 128 uint32_t /*max_num_bytes_to_write*/, | 128 uint32_t /*max_num_bytes_to_write*/, |
| 129 uint32_t /*min_num_bytes_to_write*/) { | 129 uint32_t /*min_num_bytes_to_write*/) { |
| 130 NOTREACHED(); | 130 NOTREACHED(); |
| 131 return MOJO_RESULT_INTERNAL; | 131 return MOJO_RESULT_INTERNAL; |
| 132 } | 132 } |
| 133 | 133 |
| 134 MojoResult RemoteProducerDataPipeImpl::ProducerBeginWriteData( | 134 MojoResult RemoteProducerDataPipeImpl::ProducerBeginWriteData( |
| 135 UserPointer<void*> /*buffer*/, | 135 UserPointer<void*> /*buffer*/, |
| 136 UserPointer<uint32_t> /*buffer_num_bytes*/, | 136 UserPointer<uint32_t> /*buffer_num_bytes*/) { |
| 137 uint32_t /*min_num_bytes_to_write*/) { | |
| 138 NOTREACHED(); | 137 NOTREACHED(); |
| 139 return MOJO_RESULT_INTERNAL; | 138 return MOJO_RESULT_INTERNAL; |
| 140 } | 139 } |
| 141 | 140 |
| 142 MojoResult RemoteProducerDataPipeImpl::ProducerEndWriteData( | 141 MojoResult RemoteProducerDataPipeImpl::ProducerEndWriteData( |
| 143 uint32_t /*num_bytes_written*/) { | 142 uint32_t /*num_bytes_written*/) { |
| 144 NOTREACHED(); | 143 NOTREACHED(); |
| 145 return MOJO_RESULT_INTERNAL; | 144 return MOJO_RESULT_INTERNAL; |
| 146 } | 145 } |
| 147 | 146 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 242 |
| 244 MojoResult RemoteProducerDataPipeImpl::ConsumerQueryData( | 243 MojoResult RemoteProducerDataPipeImpl::ConsumerQueryData( |
| 245 UserPointer<uint32_t> num_bytes) { | 244 UserPointer<uint32_t> num_bytes) { |
| 246 // Note: This cast is safe, since the capacity fits into a |uint32_t|. | 245 // Note: This cast is safe, since the capacity fits into a |uint32_t|. |
| 247 num_bytes.Put(static_cast<uint32_t>(current_num_bytes_)); | 246 num_bytes.Put(static_cast<uint32_t>(current_num_bytes_)); |
| 248 return MOJO_RESULT_OK; | 247 return MOJO_RESULT_OK; |
| 249 } | 248 } |
| 250 | 249 |
| 251 MojoResult RemoteProducerDataPipeImpl::ConsumerBeginReadData( | 250 MojoResult RemoteProducerDataPipeImpl::ConsumerBeginReadData( |
| 252 UserPointer<const void*> buffer, | 251 UserPointer<const void*> buffer, |
| 253 UserPointer<uint32_t> buffer_num_bytes, | 252 UserPointer<uint32_t> buffer_num_bytes) { |
| 254 uint32_t min_num_bytes_to_read) { | |
| 255 size_t max_num_bytes_to_read = GetMaxNumBytesToRead(); | 253 size_t max_num_bytes_to_read = GetMaxNumBytesToRead(); |
| 256 if (min_num_bytes_to_read > max_num_bytes_to_read) { | |
| 257 // Don't return "should wait" since you can't wait for a specified amount of | |
| 258 // data. | |
| 259 return producer_open() ? MOJO_RESULT_OUT_OF_RANGE | |
| 260 : MOJO_RESULT_FAILED_PRECONDITION; | |
| 261 } | |
| 262 | |
| 263 // Don't go into a two-phase read if there's no data. | 254 // Don't go into a two-phase read if there's no data. |
| 264 if (max_num_bytes_to_read == 0) { | 255 if (max_num_bytes_to_read == 0) { |
| 265 return producer_open() ? MOJO_RESULT_SHOULD_WAIT | 256 return producer_open() ? MOJO_RESULT_SHOULD_WAIT |
| 266 : MOJO_RESULT_FAILED_PRECONDITION; | 257 : MOJO_RESULT_FAILED_PRECONDITION; |
| 267 } | 258 } |
| 268 | 259 |
| 269 buffer.Put(buffer_.get() + start_index_); | 260 buffer.Put(buffer_.get() + start_index_); |
| 270 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_read)); | 261 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_read)); |
| 271 set_consumer_two_phase_max_num_bytes_read( | 262 set_consumer_two_phase_max_num_bytes_read( |
| 272 static_cast<uint32_t>(max_num_bytes_to_read)); | 263 static_cast<uint32_t>(max_num_bytes_to_read)); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // If the consumer is still open and we still have data, we have to keep the | 458 // If the consumer is still open and we still have data, we have to keep the |
| 468 // buffer around. Currently, we won't free it even if it empties later. (We | 459 // buffer around. Currently, we won't free it even if it empties later. (We |
| 469 // could do this -- requiring a check on every read -- but that seems to be | 460 // could do this -- requiring a check on every read -- but that seems to be |
| 470 // optimizing for the uncommon case.) | 461 // optimizing for the uncommon case.) |
| 471 if (!consumer_open() || !current_num_bytes_) | 462 if (!consumer_open() || !current_num_bytes_) |
| 472 DestroyBuffer(); | 463 DestroyBuffer(); |
| 473 } | 464 } |
| 474 | 465 |
| 475 } // namespace system | 466 } // namespace system |
| 476 } // namespace mojo | 467 } // namespace mojo |
| OLD | NEW |