| 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_consumer_data_pipe_impl.h" | 5 #include "mojo/edk/system/remote_consumer_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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // TODO(vtl): We report |num_bytes_to_write|, instead of |offset|, even if we | 170 // TODO(vtl): We report |num_bytes_to_write|, instead of |offset|, even if we |
| 171 // failed at some point. This is consistent with the idea that writes either | 171 // failed at some point. This is consistent with the idea that writes either |
| 172 // "succeed" or "fail" (and since some bytes may have been sent, we opt for | 172 // "succeed" or "fail" (and since some bytes may have been sent, we opt for |
| 173 // "succeed"). Think about this some more. | 173 // "succeed"). Think about this some more. |
| 174 num_bytes.Put(static_cast<uint32_t>(num_bytes_to_write)); | 174 num_bytes.Put(static_cast<uint32_t>(num_bytes_to_write)); |
| 175 return MOJO_RESULT_OK; | 175 return MOJO_RESULT_OK; |
| 176 } | 176 } |
| 177 | 177 |
| 178 MojoResult RemoteConsumerDataPipeImpl::ProducerBeginWriteData( | 178 MojoResult RemoteConsumerDataPipeImpl::ProducerBeginWriteData( |
| 179 UserPointer<void*> buffer, | 179 UserPointer<void*> buffer, |
| 180 UserPointer<uint32_t> buffer_num_bytes, | 180 UserPointer<uint32_t> buffer_num_bytes) { |
| 181 uint32_t min_num_bytes_to_write) { | |
| 182 DCHECK(consumer_open()); | 181 DCHECK(consumer_open()); |
| 183 DCHECK(channel_endpoint_); | 182 DCHECK(channel_endpoint_); |
| 184 | 183 |
| 185 DCHECK_LE(consumer_num_bytes_, capacity_num_bytes()); | 184 DCHECK_LE(consumer_num_bytes_, capacity_num_bytes()); |
| 186 DCHECK_EQ(consumer_num_bytes_ % element_num_bytes(), 0u); | 185 DCHECK_EQ(consumer_num_bytes_ % element_num_bytes(), 0u); |
| 187 | 186 |
| 188 size_t max_num_bytes_to_write = capacity_num_bytes() - consumer_num_bytes_; | 187 size_t max_num_bytes_to_write = capacity_num_bytes() - consumer_num_bytes_; |
| 189 if (min_num_bytes_to_write > max_num_bytes_to_write) { | |
| 190 // Don't return "should wait" since you can't wait for a specified amount | |
| 191 // of data. | |
| 192 return MOJO_RESULT_OUT_OF_RANGE; | |
| 193 } | |
| 194 | |
| 195 // Don't go into a two-phase write if there's no room. | 188 // Don't go into a two-phase write if there's no room. |
| 196 if (max_num_bytes_to_write == 0) | 189 if (max_num_bytes_to_write == 0) |
| 197 return MOJO_RESULT_SHOULD_WAIT; | 190 return MOJO_RESULT_SHOULD_WAIT; |
| 198 | 191 |
| 199 EnsureBuffer(); | 192 EnsureBuffer(); |
| 200 start_index_ = 0; // We always have the full buffer. | 193 start_index_ = 0; // We always have the full buffer. |
| 201 buffer.Put(buffer_.get()); | 194 buffer.Put(buffer_.get()); |
| 202 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_write)); | 195 buffer_num_bytes.Put(static_cast<uint32_t>(max_num_bytes_to_write)); |
| 203 set_producer_two_phase_max_num_bytes_written( | 196 set_producer_two_phase_max_num_bytes_written( |
| 204 static_cast<uint32_t>(max_num_bytes_to_write)); | 197 static_cast<uint32_t>(max_num_bytes_to_write)); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 329 } |
| 337 | 330 |
| 338 MojoResult RemoteConsumerDataPipeImpl::ConsumerQueryData( | 331 MojoResult RemoteConsumerDataPipeImpl::ConsumerQueryData( |
| 339 UserPointer<uint32_t> /*num_bytes*/) { | 332 UserPointer<uint32_t> /*num_bytes*/) { |
| 340 NOTREACHED(); | 333 NOTREACHED(); |
| 341 return MOJO_RESULT_INTERNAL; | 334 return MOJO_RESULT_INTERNAL; |
| 342 } | 335 } |
| 343 | 336 |
| 344 MojoResult RemoteConsumerDataPipeImpl::ConsumerBeginReadData( | 337 MojoResult RemoteConsumerDataPipeImpl::ConsumerBeginReadData( |
| 345 UserPointer<const void*> /*buffer*/, | 338 UserPointer<const void*> /*buffer*/, |
| 346 UserPointer<uint32_t> /*buffer_num_bytes*/, | 339 UserPointer<uint32_t> /*buffer_num_bytes*/) { |
| 347 uint32_t /*min_num_bytes_to_read*/) { | |
| 348 NOTREACHED(); | 340 NOTREACHED(); |
| 349 return MOJO_RESULT_INTERNAL; | 341 return MOJO_RESULT_INTERNAL; |
| 350 } | 342 } |
| 351 | 343 |
| 352 MojoResult RemoteConsumerDataPipeImpl::ConsumerEndReadData( | 344 MojoResult RemoteConsumerDataPipeImpl::ConsumerEndReadData( |
| 353 uint32_t /*num_bytes_read*/) { | 345 uint32_t /*num_bytes_read*/) { |
| 354 NOTREACHED(); | 346 NOTREACHED(); |
| 355 return MOJO_RESULT_INTERNAL; | 347 return MOJO_RESULT_INTERNAL; |
| 356 } | 348 } |
| 357 | 349 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 DCHECK(channel_endpoint_); | 420 DCHECK(channel_endpoint_); |
| 429 SetConsumerClosed(); | 421 SetConsumerClosed(); |
| 430 channel_endpoint_->DetachFromClient(); | 422 channel_endpoint_->DetachFromClient(); |
| 431 channel_endpoint_ = nullptr; | 423 channel_endpoint_ = nullptr; |
| 432 if (!producer_in_two_phase_write()) | 424 if (!producer_in_two_phase_write()) |
| 433 DestroyBuffer(); | 425 DestroyBuffer(); |
| 434 } | 426 } |
| 435 | 427 |
| 436 } // namespace system | 428 } // namespace system |
| 437 } // namespace mojo | 429 } // namespace mojo |
| OLD | NEW |