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

Unified Diff: mojo/system/local_data_pipe.cc

Issue 118873004: Mojo: DataPipe: Write some docs and rationalize some return values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixes Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/system/core.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/local_data_pipe.cc
diff --git a/mojo/system/local_data_pipe.cc b/mojo/system/local_data_pipe.cc
index 36ba55272e7b51f2d31c5073313fb78a673a76fb..334f597f23e0db58057f3af94fc61655e01b196d 100644
--- a/mojo/system/local_data_pipe.cc
+++ b/mojo/system/local_data_pipe.cc
@@ -50,6 +50,7 @@ MojoResult LocalDataPipe::ProducerWriteDataImplNoLock(const void* elements,
bool all_or_none) {
DCHECK_EQ(*num_bytes % element_num_bytes(), 0u);
DCHECK_GT(*num_bytes, 0u);
+ DCHECK(consumer_open_no_lock());
size_t num_bytes_to_write = 0;
if (may_discard()) {
@@ -68,8 +69,9 @@ MojoResult LocalDataPipe::ProducerWriteDataImplNoLock(const void* elements,
}
} else {
if (all_or_none && *num_bytes > capacity_num_bytes() - current_num_bytes_) {
- return (*num_bytes > capacity_num_bytes()) ? MOJO_RESULT_OUT_OF_RANGE :
- MOJO_RESULT_SHOULD_WAIT;
+ // Don't return "should wait" since you can't wait for a specified amount
+ // of data.
+ return MOJO_RESULT_OUT_OF_RANGE;
}
num_bytes_to_write = std::min(static_cast<size_t>(*num_bytes),
@@ -110,10 +112,14 @@ MojoResult LocalDataPipe::ProducerBeginWriteDataImplNoLock(
void** buffer,
uint32_t* buffer_num_bytes,
bool all_or_none) {
+ DCHECK(consumer_open_no_lock());
+
size_t max_num_bytes_to_write = GetMaxNumBytesToWriteNoLock();
- // TODO(vtl): Consider this return value.
- if (all_or_none && *buffer_num_bytes > max_num_bytes_to_write)
+ if (all_or_none && *buffer_num_bytes > max_num_bytes_to_write) {
+ // Don't return "should wait" since you can't wait for a specified amount of
+ // data.
return MOJO_RESULT_OUT_OF_RANGE;
+ }
// Don't go into a two-phase write if there's no room.
if (max_num_bytes_to_write == 0)
@@ -179,9 +185,12 @@ MojoResult LocalDataPipe::ConsumerReadDataImplNoLock(void* elements,
DCHECK_EQ(*num_bytes % element_num_bytes(), 0u);
DCHECK_GT(*num_bytes, 0u);
- // TODO(vtl): Think about the error code in this case.
- if (all_or_none && *num_bytes > current_num_bytes_)
- return MOJO_RESULT_OUT_OF_RANGE;
+ if (all_or_none && *num_bytes > current_num_bytes_) {
+ // Don't return "should wait" since you can't wait for a specified amount of
+ // data.
+ return producer_open_no_lock() ? MOJO_RESULT_OUT_OF_RANGE :
+ MOJO_RESULT_FAILED_PRECONDITION;
+ }
size_t num_bytes_to_read =
std::min(static_cast<size_t>(*num_bytes), current_num_bytes_);
@@ -220,9 +229,12 @@ MojoResult LocalDataPipe::ConsumerDiscardDataImplNoLock(uint32_t* num_bytes,
DCHECK_EQ(*num_bytes % element_num_bytes(), 0u);
DCHECK_GT(*num_bytes, 0u);
- // TODO(vtl): Think about the error code in this case.
- if (all_or_none && *num_bytes > current_num_bytes_)
- return MOJO_RESULT_OUT_OF_RANGE;
+ if (all_or_none && *num_bytes > current_num_bytes_) {
+ // Don't return "should wait" since you can't wait for a specified amount of
+ // data.
+ return producer_open_no_lock() ? MOJO_RESULT_OUT_OF_RANGE :
+ MOJO_RESULT_FAILED_PRECONDITION;
+ }
// Be consistent with other operations; error if no data available.
if (current_num_bytes_ == 0) {
@@ -255,9 +267,11 @@ MojoResult LocalDataPipe::ConsumerBeginReadDataImplNoLock(
uint32_t* buffer_num_bytes,
bool all_or_none) {
size_t max_num_bytes_to_read = GetMaxNumBytesToReadNoLock();
- // TODO(vtl): Consider this return value.
- if (all_or_none && *buffer_num_bytes > max_num_bytes_to_read)
+ if (all_or_none && *buffer_num_bytes > max_num_bytes_to_read) {
+ // Don't return "should wait" since you can't wait for a specified amount of
+ // data.
return MOJO_RESULT_OUT_OF_RANGE;
+ }
// Don't go into a two-phase read if there's no data.
if (max_num_bytes_to_read == 0) {
« no previous file with comments | « mojo/public/system/core.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698