Commit 6e49b250 authored by miu's avatar miu Committed by Commit bot

Mojo: Fix data pipe ALL_OR_NONE write capacity check.

Fixes a bug where ALL_OR_NONE writes to data pipes were checking the
total capacity of the pipe, rather than the available capacity. The bug
allowed ALL_OR_NONE writes to succeed (MOJO_RESULT_OK), but in actuality
only a portion of the data was written.

Updated unit test with a case that fails w/o the fix, but passes with
the fix.

Review-Url: https://codereview.chromium.org/2341633005
Cr-Commit-Position: refs/heads/master@{#418929}
parent b31cb383
......@@ -137,9 +137,8 @@ MojoResult DataPipeProducerDispatcher::WriteData(const void* elements,
if (*num_bytes == 0)
return MOJO_RESULT_OK; // Nothing to do.
bool all_or_none = flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE;
uint32_t min_num_bytes_to_write = all_or_none ? *num_bytes : 0;
if (min_num_bytes_to_write > options_.capacity_num_bytes) {
if ((flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE) &&
(*num_bytes > available_capacity_)) {
// Don't return "should wait" since you can't wait for a specified amount of
// data.
return MOJO_RESULT_OUT_OF_RANGE;
......
......@@ -799,7 +799,7 @@ TEST_F(DataPipeTest, AllOrNone) {
ASSERT_EQ(MOJO_RESULT_OK, Create(&options));
MojoHandleSignalsState hss;
// Try writing way too much.
// Try writing more than the total capacity of the pipe.
uint32_t num_bytes = 20u * sizeof(int32_t);
int32_t buffer[100];
Seq(0, arraysize(buffer), buffer);
......@@ -834,12 +834,11 @@ TEST_F(DataPipeTest, AllOrNone) {
ASSERT_EQ(MOJO_RESULT_OK, QueryData(&num_bytes));
ASSERT_EQ(5u * sizeof(int32_t), num_bytes);
/* TODO(jam): enable if we end up observing max capacity
// Too much.
// Try writing more than the available capacity of the pipe, but less than the
// total capacity.
num_bytes = 6u * sizeof(int32_t);
Seq(200, arraysize(buffer), buffer);
ASSERT_EQ(MOJO_RESULT_OUT_OF_RANGE, WriteData(buffer, &num_bytes, true));
*/
// Try reading too much.
num_bytes = 11u * sizeof(int32_t);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment