Remove support for "all or none" two-phase data pipe read/write.
(Will clean up/simplify the rest of mojo/edk/system separately.)
BUG=#366
R=jamesr@chromium.org, rogulenko@google.com
Review URL: https://codereview.chromium.org/1374463002 .
diff --git a/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc
index 0ef0aa1..57495d8 100644
--- a/mojo/edk/system/core_unittest.cc
+++ b/mojo/edk/system/core_unittest.cc
@@ -997,12 +997,12 @@
MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_PEEK));
- // Read the remaining two characters, in two-phase mode (all-or-none).
+ // Read the remaining two characters, in two-phase mode.
num_bytes = 2;
ASSERT_EQ(MOJO_RESULT_OK,
core()->BeginReadData(ch, MakeUserPointer(&read_ptr),
MakeUserPointer(&num_bytes),
- MOJO_READ_DATA_FLAG_ALL_OR_NONE));
+ MOJO_READ_DATA_FLAG_NONE));
// Note: Count on still being able to do the contiguous read here.
ASSERT_EQ(2u, num_bytes);
@@ -1236,7 +1236,7 @@
ASSERT_EQ(MOJO_RESULT_OK,
core()->BeginReadData(ch, MakeUserPointer(&read_ptr),
MakeUserPointer(&num_bytes),
- MOJO_READ_DATA_FLAG_ALL_OR_NONE));
+ MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_BUSY,
core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
kHelloSize, MakeUserPointer(&ch), 1,
diff --git a/mojo/edk/system/data_pipe_consumer_dispatcher.cc b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
index 5a1bafb..0821c64 100644
--- a/mojo/edk/system/data_pipe_consumer_dispatcher.cc
+++ b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
@@ -107,12 +107,13 @@
mutex().AssertHeld();
// These flags may not be used in two-phase mode.
- if ((flags & MOJO_READ_DATA_FLAG_DISCARD) ||
+ if ((flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE) ||
+ (flags & MOJO_READ_DATA_FLAG_DISCARD) ||
(flags & MOJO_READ_DATA_FLAG_QUERY) || (flags & MOJO_READ_DATA_FLAG_PEEK))
return MOJO_RESULT_INVALID_ARGUMENT;
- return data_pipe_->ConsumerBeginReadData(
- buffer, buffer_num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE));
+ // TODO(vtl): Remove all-or-none support at lower levels.
+ return data_pipe_->ConsumerBeginReadData(buffer, buffer_num_bytes, false);
}
MojoResult DataPipeConsumerDispatcher::EndReadDataImplNoLock(
diff --git a/mojo/edk/system/data_pipe_producer_dispatcher.cc b/mojo/edk/system/data_pipe_producer_dispatcher.cc
index ddb8b9f..536dace 100644
--- a/mojo/edk/system/data_pipe_producer_dispatcher.cc
+++ b/mojo/edk/system/data_pipe_producer_dispatcher.cc
@@ -84,8 +84,12 @@
MojoWriteDataFlags flags) {
mutex().AssertHeld();
- return data_pipe_->ProducerBeginWriteData(
- buffer, buffer_num_bytes, (flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
+ // This flag may not be used in two-phase mode.
+ if ((flags & MOJO_WRITE_DATA_FLAG_ALL_OR_NONE))
+ return MOJO_RESULT_INVALID_ARGUMENT;
+
+ // TODO(vtl): Remove all-or-none support at lower levels.
+ return data_pipe_->ProducerBeginWriteData(buffer, buffer_num_bytes, false);
}
MojoResult DataPipeProducerDispatcher::EndWriteDataImplNoLock(
diff --git a/mojo/go/tests/system_test.go b/mojo/go/tests/system_test.go
index 9ed5f4c..c488066 100644
--- a/mojo/go/tests/system_test.go
+++ b/mojo/go/tests/system_test.go
@@ -205,9 +205,9 @@
// Test two-phase read/write.
// Writing.
kHello = []byte("Hello, world!")
- r, buf := hp.BeginWriteData(len(kHello), system.MOJO_WRITE_DATA_FLAG_NONE)
+ r, buf := hp.BeginWriteData(system.MOJO_WRITE_DATA_FLAG_NONE)
if r != system.MOJO_RESULT_OK {
- t.Fatalf("Failed BeginWriteData on hp:%v numBytes:%d", r, len(kHello))
+ t.Fatalf("Failed BeginWriteData on hp:%v", r)
}
if len(buf) < len(kHello) {
t.Fatalf("Buffer size(%d) should be at least %d", len(buf), len(kHello))
@@ -226,8 +226,8 @@
if r, _ = hc.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, system.MOJO_DEADLINE_INDEFINITE); r != system.MOJO_RESULT_OK {
t.Fatalf("hc should be readable after EndWriteData on hp:%v", r)
}
- if r, buf = hc.BeginReadData(len(kHello), system.MOJO_READ_DATA_FLAG_NONE); r != system.MOJO_RESULT_OK {
- t.Fatalf("Failed BeginReadData on hc:%v numBytes:%d", r, len(kHello))
+ if r, buf = hc.BeginReadData(system.MOJO_READ_DATA_FLAG_NONE); r != system.MOJO_RESULT_OK {
+ t.Fatalf("Failed BeginReadData on hc:%v", r)
}
if len(buf) != len(kHello) {
t.Fatalf("Buffer size(%d) should be equal to %d", len(buf), len(kHello))
diff --git a/mojo/public/c/system/data_pipe.h b/mojo/public/c/system/data_pipe.h
index 54cfea8..3efe1c7 100644
--- a/mojo/public/c/system/data_pipe.h
+++ b/mojo/public/c/system/data_pipe.h
@@ -139,14 +139,6 @@
// On success, |*num_bytes| is set to the amount of data that was actually
// written.
//
-// Note: If the data pipe has the "may discard" option flag (specified on
-// creation), this will discard as much data as required to write the given
-// data, starting with the earliest written data that has not been consumed.
-// However, even with "may discard", if |*num_bytes| is greater than the data
-// pipe's capacity (and |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| is not set), this
-// will write the maximum amount possible (namely, the data pipe's capacity) and
-// set |*num_bytes| to that amount. It will *not* discard data from |elements|.
-//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
@@ -167,56 +159,43 @@
//
// TODO(vtl): Should there be a way of querying how much data can be written?
MOJO_SYSTEM_EXPORT MojoResult
- MojoWriteData(MojoHandle data_pipe_producer_handle,
- const void* elements,
- uint32_t* num_bytes, // In/out.
- MojoWriteDataFlags flags);
+MojoWriteData(MojoHandle data_pipe_producer_handle,
+ const void* elements,
+ uint32_t* num_bytes, // In/out.
+ MojoWriteDataFlags flags);
// Begins a two-phase write to the data pipe producer given by
// |data_pipe_producer_handle|. On success, |*buffer| will be a pointer to which
-// the caller can write |*buffer_num_bytes| bytes of data. If flags has
-// |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set, then the output value
-// |*buffer_num_bytes| will be at least as large as its input value, which must
-// also be a multiple of the element size (if |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE|
-// is not set, the input value of |*buffer_num_bytes| is ignored).
+// the caller can write |*buffer_num_bytes| bytes of data. There are currently
+// no flags allowed, so |flags| should be |MOJO_WRITE_DATA_FLAG_NONE|.
//
// During a two-phase write, |data_pipe_producer_handle| is *not* writable.
// E.g., if another thread tries to write to it, it will get |MOJO_RESULT_BUSY|;
// that thread can then wait for |data_pipe_producer_handle| to become writable
// again.
//
-// When |MojoBeginWriteData()| returns MOJO_RESULT_OK, and the caller has
+// When |MojoBeginWriteData()| returns |MOJO_RESULT_OK|, and the caller has
// finished writing data to |*buffer|, it should call |MojoEndWriteData()| to
// specify the amount written and to complete the two-phase write.
// |MojoEndWriteData()| need not be called for other return values.
//
-// Note: If the data pipe has the "may discard" option flag (specified on
-// creation) and |flags| has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set, this may
-// discard some data.
-//
// Returns:
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
// |data_pipe_producer_handle| is not a handle to a data pipe producer or
-// flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and
-// |*buffer_num_bytes| is not a multiple of the element size).
+// flags has |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set).
// |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer handle has been
// closed.
-// |MOJO_RESULT_OUT_OF_RANGE| if |flags| has
-// |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set and the required amount of data
-// (specified by |*buffer_num_bytes|) cannot be written contiguously at
-// this time. (Note that there may be space available for the required
-// amount of data, but the "next" write position may not be large enough.)
// |MOJO_RESULT_BUSY| if there is already a two-phase write ongoing with
// |data_pipe_producer_handle| (i.e., |MojoBeginWriteData()| has been
// called, but not yet the matching |MojoEndWriteData()|).
// |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the
// consumer is still open).
MOJO_SYSTEM_EXPORT MojoResult
- MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
- void** buffer, // Out.
- uint32_t* buffer_num_bytes, // In/out.
- MojoWriteDataFlags flags);
+MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
+ void** buffer, // Out.
+ uint32_t* buffer_num_bytes, // Out.
+ MojoWriteDataFlags flags);
// Ends a two-phase write to the data pipe producer given by
// |data_pipe_producer_handle| that was begun by a call to
@@ -241,8 +220,8 @@
// two-phase write (e.g., |MojoBeginWriteData()| was not called or
// |MojoEndWriteData()| has already been called).
MOJO_SYSTEM_EXPORT MojoResult
- MojoEndWriteData(MojoHandle data_pipe_producer_handle,
- uint32_t num_bytes_written);
+MojoEndWriteData(MojoHandle data_pipe_producer_handle,
+ uint32_t num_bytes_written);
// Reads data from the data pipe consumer given by |data_pipe_consumer_handle|.
// May also be used to discard data or query the amount of data available.
@@ -295,13 +274,8 @@
// Begins a two-phase read from the data pipe consumer given by
// |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer from
-// which the caller can read |*buffer_num_bytes| bytes of data. If flags has
-// |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, then the output value
-// |*buffer_num_bytes| will be at least as large as its input value, which must
-// also be a multiple of the element size (if |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
-// is not set, the input value of |*buffer_num_bytes| is ignored). |flags| must
-// not have |MOJO_READ_DATA_FLAG_DISCARD|, |MOJO_READ_DATA_FLAG_QUERY|, or
-// |MOJO_READ_DATA_FLAG_PEEK| set.
+// which the caller can read |*buffer_num_bytes| bytes of data. There are
+// currently no valid flags, so |flags| must be |MOJO_READ_DATA_FLAG_NONE|.
//
// During a two-phase read, |data_pipe_consumer_handle| is *not* readable.
// E.g., if another thread tries to read from it, it will get
@@ -316,25 +290,19 @@
// |MOJO_RESULT_OK| on success.
// |MOJO_RESULT_INVALID_ARGUMENT| if some argument was invalid (e.g.,
// |data_pipe_consumer_handle| is not a handle to a data pipe consumer,
-// |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set and
-// |*buffer_num_bytes| is not a multiple of the element size, or |flags|
-// has invalid flags set).
+// or |flags| has invalid flags set).
// |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer handle has been
// closed.
-// |MOJO_RESULT_OUT_OF_RANGE| if |flags| has |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
-// set and the required amount of data (specified by |*buffer_num_bytes|)
-// cannot be read from a contiguous buffer at this time. (Note that there
-// may be the required amount of data, but it may not be contiguous.)
// |MOJO_RESULT_BUSY| if there is already a two-phase read ongoing with
// |data_pipe_consumer_handle| (i.e., |MojoBeginReadData()| has been
// called, but not yet the matching |MojoEndReadData()|).
// |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the
// producer is still open).
MOJO_SYSTEM_EXPORT MojoResult
- MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
- const void** buffer, // Out.
- uint32_t* buffer_num_bytes, // In/out.
- MojoReadDataFlags flags);
+MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
+ const void** buffer, // Out.
+ uint32_t* buffer_num_bytes, // Out.
+ MojoReadDataFlags flags);
// Ends a two-phase read from the data pipe consumer given by
// |data_pipe_consumer_handle| that was begun by a call to |MojoBeginReadData()|
@@ -356,8 +324,7 @@
// two-phase read (e.g., |MojoBeginReadData()| was not called or
// |MojoEndReadData()| has already been called).
MOJO_SYSTEM_EXPORT MojoResult
- MojoEndReadData(MojoHandle data_pipe_consumer_handle,
- uint32_t num_bytes_read);
+MojoEndReadData(MojoHandle data_pipe_consumer_handle, uint32_t num_bytes_read);
#ifdef __cplusplus
} // extern "C"
diff --git a/mojo/public/go/bindings/invalid_handle.go b/mojo/public/go/bindings/invalid_handle.go
index 1acc645..64d4645 100644
--- a/mojo/public/go/bindings/invalid_handle.go
+++ b/mojo/public/go/bindings/invalid_handle.go
@@ -56,7 +56,7 @@
return system.MOJO_RESULT_INVALID_ARGUMENT, nil
}
-func (h *InvalidHandle) BeginReadData(numBytes int, flags system.MojoReadDataFlags) (system.MojoResult, []byte) {
+func (h *InvalidHandle) BeginReadData(flags system.MojoReadDataFlags) (system.MojoResult, []byte) {
return system.MOJO_RESULT_INVALID_ARGUMENT, nil
}
@@ -68,7 +68,7 @@
return system.MOJO_RESULT_INVALID_ARGUMENT, 0
}
-func (h *InvalidHandle) BeginWriteData(numBytes int, flags system.MojoWriteDataFlags) (system.MojoResult, []byte) {
+func (h *InvalidHandle) BeginWriteData(flags system.MojoWriteDataFlags) (system.MojoResult, []byte) {
return system.MOJO_RESULT_INVALID_ARGUMENT, nil
}
diff --git a/mojo/public/go/system/data_pipe.go b/mojo/public/go/system/data_pipe.go
index c585553..3f331b2 100644
--- a/mojo/public/go/system/data_pipe.go
+++ b/mojo/public/go/system/data_pipe.go
@@ -14,10 +14,8 @@
// BeginReadData begins a two-phase read from the data pipe consumer.
// On success, returns a slice from which the caller can read up to its
- // length bytes of data. If flags has |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
- // set, then the slice length will be at least as large as |numBytes|,
- // which must also be a multiple of the element size (otherwise the
- // caller must check the length of the slice).
+ // length bytes of data. The slice length will always be a multiple of
+ // the element size.
//
// During a two-phase read, this handle is *not* readable. E.g., read
// from this handle will return |MOJO_RESULT_BUSY|.
@@ -25,7 +23,7 @@
// Once the caller has finished reading data from the slice, it should
// call |EndReadData()| to specify the amount read and to complete the
// two-phase read.
- BeginReadData(numBytes int, flags MojoReadDataFlags) (MojoResult, []byte)
+ BeginReadData(flags MojoReadDataFlags) (MojoResult, []byte)
// EndReadData ends a two-phase read from the data pipe consumer that
// was begun by a call to |BeginReadData()| on the same handle.
@@ -48,11 +46,8 @@
WriteData(data []byte, flags MojoWriteDataFlags) (MojoResult, int)
// BeginWriteData begins a two-phase write to the data pipe producer.
- // On success, returns a slice to which the caller can write. If flags
- // has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, then the slice length will
- // be at least as large as |numBytes|, which must also be a multiple of
- // the element size (otherwise the caller must check the length of the
- // slice).
+ // On success, returns a slice to which the caller can write. The slice
+ // length will always be a multiple of the element size.
//
// During a two-phase write, this handle is *not* writable. E.g., write
// to this handle will return |MOJO_RESULT_BUSY|.
@@ -60,7 +55,7 @@
// Once the caller has finished writing data to the buffer, it should
// call |EndWriteData()| to specify the amount written and to complete
// the two-phase write.
- BeginWriteData(numBytes int, flags MojoWriteDataFlags) (MojoResult, []byte)
+ BeginWriteData(flags MojoWriteDataFlags) (MojoResult, []byte)
// EndWriteData ends a two-phase write to the data pipe producer that
// was begun by a call to |BeginWriteData()| on the same handle.
@@ -89,9 +84,9 @@
return MojoResult(r), buf
}
-func (h *dataPipeConsumer) BeginReadData(numBytes int, flags MojoReadDataFlags) (MojoResult, []byte) {
+func (h *dataPipeConsumer) BeginReadData(flags MojoReadDataFlags) (MojoResult, []byte) {
h.core.mu.Lock()
- r, buf := sysImpl.BeginReadData(uint32(h.mojoHandle), uint32(numBytes), uint32(flags))
+ r, buf := sysImpl.BeginReadData(uint32(h.mojoHandle), uint32(flags))
h.core.mu.Unlock()
return MojoResult(r), buf
}
@@ -116,9 +111,9 @@
return MojoResult(r), int(bytesWritten)
}
-func (h *dataPipeProducer) BeginWriteData(numBytes int, flags MojoWriteDataFlags) (MojoResult, []byte) {
+func (h *dataPipeProducer) BeginWriteData(flags MojoWriteDataFlags) (MojoResult, []byte) {
h.core.mu.Lock()
- r, buf := sysImpl.BeginWriteData(uint32(h.mojoHandle), uint32(numBytes), uint32(flags))
+ r, buf := sysImpl.BeginWriteData(uint32(h.mojoHandle), uint32(flags))
h.core.mu.Unlock()
return MojoResult(r), buf
}
diff --git a/mojo/public/go/system/system.go b/mojo/public/go/system/system.go
index 9481c07..efcc397 100644
--- a/mojo/public/go/system/system.go
+++ b/mojo/public/go/system/system.go
@@ -20,11 +20,11 @@
CreateDataPipe(flags, elementNumBytes, capacityNumBytes uint32) (result uint32, producerHandle, consumerHandle uint32)
CreateDataPipeWithDefaultOptions() (result uint32, producerHandle, consumerHandle uint32)
WriteData(producerHandle uint32, buf []byte, flags uint32) (result uint32, bytesWritten uint32)
- BeginWriteData(producerHandle uint32, numBytes uint32, flags uint32) (result uint32, buf []byte)
+ BeginWriteData(producerHandle uint32, flags uint32) (result uint32, buf []byte)
EndWriteData(producerHandle uint32, numBytesWritten uint32) (result uint32)
ReadData(consumerHandle, flags uint32) (result uint32, buf []byte)
- BeginReadData(consumerHandle uint32, numBytes uint32, flags uint32) (result uint32, buf []byte)
+ BeginReadData(consumerHandle uint32, flags uint32) (result uint32, buf []byte)
EndReadData(consumerHandle uint32, numBytesRead uint32) (result uint32)
// Time
diff --git a/mojo/public/platform/native_cgo/system_cgo.go b/mojo/public/platform/native_cgo/system_cgo.go
index 48594ba..732b18f 100644
--- a/mojo/public/platform/native_cgo/system_cgo.go
+++ b/mojo/public/platform/native_cgo/system_cgo.go
@@ -122,9 +122,9 @@
return uint32(r), uint32(numBytes)
}
-func (c *CGoSystem) BeginWriteData(producerHandle uint32, numBytes uint32, flags uint32) (result uint32, buf []byte) {
+func (c *CGoSystem) BeginWriteData(producerHandle uint32, flags uint32) (result uint32, buf []byte) {
var buffer unsafe.Pointer
- bufferNumBytes := C.uint32_t(numBytes)
+ var bufferNumBytes C.uint32_t
r := C.MojoBeginWriteData(C.MojoHandle(producerHandle), &buffer, &bufferNumBytes, C.MojoWriteDataFlags(flags))
if r != C.MOJO_RESULT_OK {
return uint32(r), nil
@@ -147,9 +147,9 @@
return uint32(r), buf
}
-func (c *CGoSystem) BeginReadData(consumerHandle uint32, numBytes uint32, flags uint32) (result uint32, buf []byte) {
+func (c *CGoSystem) BeginReadData(consumerHandle uint32, flags uint32) (result uint32, buf []byte) {
var buffer unsafe.Pointer
- bufferNumBytes := C.uint32_t(numBytes)
+ var bufferNumBytes C.uint32_t
r := C.MojoBeginReadData(C.MojoHandle(consumerHandle), &buffer, &bufferNumBytes, C.MojoReadDataFlags(flags))
if r != C.MOJO_RESULT_OK {
return uint32(r), nil