Index: mojo/public/go/system/data_pipe.go |
diff --git a/mojo/public/go/system/data_pipe.go b/mojo/public/go/system/data_pipe.go |
index 7de27d13eea0be2a6b2adb48b8df56c390b7b18f..b79a1e0395c965452f96dcbbeccb3196c39b0e81 100644 |
--- a/mojo/public/go/system/data_pipe.go |
+++ b/mojo/public/go/system/data_pipe.go |
@@ -16,6 +16,31 @@ type ConsumerHandle interface { |
// ReadData reads data from the data pipe consumer handle with the |
// given flags. On success, returns the data that was read. |
ReadData(flags MojoReadDataFlags) (MojoResult, []byte) |
+ |
+ // 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). |
+ // |
+ // During a two-phase read, this handle is *not* readable. E.g., read |
+ // from this handle will return |MOJO_RESULT_BUSY|. |
+ // |
+ // 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) |
+ |
+ // EndReadData ends a two-phase read from the data pipe consumer that |
+ // was begun by a call to |BeginReadData()| on the same handle. |
+ // |numBytesRead| should indicate the amount of data actually read; it |
+ // must be less than or equal to the length of the slice returned by |
+ // |BeginReadData()| and must be a multiple of the element size. |
+ // |
+ // On failure, the two-phase read (if any) is ended (so the handle may |
+ // become readable again) but no data is "removed" from the data pipe. |
+ EndReadData(numBytesRead int) MojoResult |
} |
// ProducerHandle is a handle for the producer part of a data pipe. |
@@ -26,6 +51,34 @@ type ProducerHandle interface { |
// given flags. On success, returns the number of bytes that were |
// actually written. |
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). |
+ // |
+ // During a two-phase write, this handle is *not* writable. E.g., write |
+ // to this handle will return |MOJO_RESULT_BUSY|. |
+ // |
+ // 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) |
+ |
+ // EndWriteData ends a two-phase write to the data pipe producer that |
+ // was begun by a call to |BeginWriteData()| on the same handle. |
+ // |numBytesWritten| should indicate the amount of data actually |
+ // written; it must be less than or equal to the length of the slice |
+ // returned by |BeginWriteData()| and must be a multiple of the element |
+ // size. The slice returned from |BeginWriteData()| must have been |
+ // filled with exactly |numBytesWritten| bytes of data. |
+ // |
+ // On failure, the two-phase write (if any) is ended (so the handle may |
+ // become writable again, if there's space available) but no data |
+ // written to the slice is "put into" the data pipe. |
+ EndWriteData(numBytesWritten int) MojoResult |
} |
type dataPipeConsumer struct { |
@@ -49,6 +102,19 @@ func (h *dataPipeConsumer) ReadData(flags MojoReadDataFlags) (MojoResult, []byte |
return MojoResult(result), data |
} |
+func (h *dataPipeConsumer) BeginReadData(numBytes int, flags MojoReadDataFlags) (MojoResult, []byte) { |
+ cParams := C.MallocTwoPhaseActionParams() |
+ defer C.FreeTwoPhaseActionParams(cParams) |
+ *cParams.num_bytes = C.uint32_t(numBytes) |
+ result := C.MojoBeginReadData(h.mojoHandle.cValue(), cParams.buffer, cParams.num_bytes, flags.cValue()) |
+ buffer := unsafeByteSlice(unsafe.Pointer(*cParams.buffer), int(*cParams.num_bytes)) |
+ return MojoResult(result), buffer |
+} |
+ |
+func (h *dataPipeConsumer) EndReadData(numBytesRead int) MojoResult { |
+ return MojoResult(C.MojoEndReadData(h.mojoHandle.cValue(), C.uint32_t(numBytesRead))) |
+} |
+ |
type dataPipeProducer struct { |
baseHandle |
} |
@@ -62,3 +128,16 @@ func (h *dataPipeProducer) WriteData(data []byte, flags MojoWriteDataFlags) (Moj |
result := C.MojoWriteData(h.mojoHandle.cValue(), cParams.elements, cParams.num_bytes, flags.cValue()) |
return MojoResult(result), int(*cParams.num_bytes) |
} |
+ |
+func (h *dataPipeProducer) BeginWriteData(numBytes int, flags MojoWriteDataFlags) (MojoResult, []byte) { |
+ cParams := C.MallocTwoPhaseActionParams() |
+ defer C.FreeTwoPhaseActionParams(cParams) |
+ *cParams.num_bytes = C.uint32_t(numBytes) |
+ result := C.MojoBeginWriteData(h.mojoHandle.cValue(), cParams.buffer, cParams.num_bytes, flags.cValue()) |
+ buffer := unsafeByteSlice(unsafe.Pointer(*cParams.buffer), int(*cParams.num_bytes)) |
+ return MojoResult(result), buffer |
+} |
+ |
+func (h *dataPipeProducer) EndWriteData(numBytesWritten int) MojoResult { |
+ return MojoResult(C.MojoEndWriteData(h.mojoHandle.cValue(), C.uint32_t(numBytesWritten))) |
+} |