Let MojoSetDataPipeConsumerOptions() take null options.
The header defining it says that doing so means reset back to the
default options. I forgot about this when implementing it. Oops. :-/
R=vardhan@google.com
BUG=#442
Review URL: https://codereview.chromium.org/1865663002 .
diff --git a/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc
index 0fdd5ac..bb8967a 100644
--- a/mojo/edk/system/core_unittest.cc
+++ b/mojo/edk/system/core_unittest.cc
@@ -1250,11 +1250,9 @@
EXPECT_EQ(kCoptsSize, copts.struct_size);
EXPECT_EQ(16u, copts.read_threshold_num_bytes);
- // Default read threshold.
- copts.struct_size = kCoptsSize;
- copts.read_threshold_num_bytes = 0;
+ // Can also set to default by passing null.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->SetDataPipeConsumerOptions(ch, MakeUserPointer(&copts)));
+ core()->SetDataPipeConsumerOptions(ch, NullUserPointer()));
copts = MojoDataPipeConsumerOptions();
EXPECT_EQ(MOJO_RESULT_OK, core()->GetDataPipeConsumerOptions(
ch, MakeUserPointer(&copts), kCoptsSize));
diff --git a/mojo/edk/system/data_pipe_consumer_dispatcher.cc b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
index 5d10c77..2b3aed0 100644
--- a/mojo/edk/system/data_pipe_consumer_dispatcher.cc
+++ b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
@@ -79,16 +79,21 @@
UserPointer<const MojoDataPipeConsumerOptions> options) {
mutex().AssertHeld();
- UserOptionsReader<MojoDataPipeConsumerOptions> reader(options);
- if (!reader.is_valid())
- return MOJO_RESULT_INVALID_ARGUMENT;
+ // The default of 0 means 1 element (however big that is).
+ uint32_t read_threshold_num_bytes = 0;
+ if (!options.IsNull()) {
+ UserOptionsReader<MojoDataPipeConsumerOptions> reader(options);
+ if (!reader.is_valid())
+ return MOJO_RESULT_INVALID_ARGUMENT;
- if (!OPTIONS_STRUCT_HAS_MEMBER(MojoDataPipeConsumerOptions,
- read_threshold_num_bytes, reader))
- return MOJO_RESULT_OK;
+ if (!OPTIONS_STRUCT_HAS_MEMBER(MojoDataPipeConsumerOptions,
+ read_threshold_num_bytes, reader))
+ return MOJO_RESULT_OK;
- return data_pipe_->ConsumerSetOptions(
- reader.options().read_threshold_num_bytes);
+ read_threshold_num_bytes = reader.options().read_threshold_num_bytes;
+ }
+
+ return data_pipe_->ConsumerSetOptions(read_threshold_num_bytes);
}
MojoResult DataPipeConsumerDispatcher::GetDataPipeConsumerOptionsImplNoLock(