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

Side by Side Diff: mojo/public/go/system/data_pipe.go

Issue 1374463002: Remove support for "all or none" two-phase data pipe read/write. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package system 5 package system
6 6
7 // ConsumerHandle is a handle for the consumer part of a data pipe. 7 // ConsumerHandle is a handle for the consumer part of a data pipe.
8 type ConsumerHandle interface { 8 type ConsumerHandle interface {
9 Handle 9 Handle
10 10
11 // ReadData reads data from the data pipe consumer handle with the 11 // ReadData reads data from the data pipe consumer handle with the
12 // given flags. On success, returns the data that was read. 12 // given flags. On success, returns the data that was read.
13 ReadData(flags MojoReadDataFlags) (MojoResult, []byte) 13 ReadData(flags MojoReadDataFlags) (MojoResult, []byte)
14 14
15 // BeginReadData begins a two-phase read from the data pipe consumer. 15 // BeginReadData begins a two-phase read from the data pipe consumer.
16 // On success, returns a slice from which the caller can read up to its 16 // On success, returns a slice from which the caller can read up to its
17 » // length bytes of data. If flags has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| 17 » // length bytes of data. The slice length will always be a multiple of
18 » // set, then the slice length will be at least as large as |numBytes|, 18 » // the element size.
19 » // which must also be a multiple of the element size (otherwise the
20 » // caller must check the length of the slice).
21 // 19 //
22 // During a two-phase read, this handle is *not* readable. E.g., read 20 // During a two-phase read, this handle is *not* readable. E.g., read
23 // from this handle will return |MOJO_RESULT_BUSY|. 21 // from this handle will return |MOJO_RESULT_BUSY|.
24 // 22 //
25 // Once the caller has finished reading data from the slice, it should 23 // Once the caller has finished reading data from the slice, it should
26 // call |EndReadData()| to specify the amount read and to complete the 24 // call |EndReadData()| to specify the amount read and to complete the
27 // two-phase read. 25 // two-phase read.
28 » BeginReadData(numBytes int, flags MojoReadDataFlags) (MojoResult, []byte ) 26 » BeginReadData(flags MojoReadDataFlags) (MojoResult, []byte)
29 27
30 // EndReadData ends a two-phase read from the data pipe consumer that 28 // EndReadData ends a two-phase read from the data pipe consumer that
31 // was begun by a call to |BeginReadData()| on the same handle. 29 // was begun by a call to |BeginReadData()| on the same handle.
32 // |numBytesRead| should indicate the amount of data actually read; it 30 // |numBytesRead| should indicate the amount of data actually read; it
33 // must be less than or equal to the length of the slice returned by 31 // must be less than or equal to the length of the slice returned by
34 // |BeginReadData()| and must be a multiple of the element size. 32 // |BeginReadData()| and must be a multiple of the element size.
35 // 33 //
36 // On failure, the two-phase read (if any) is ended (so the handle may 34 // On failure, the two-phase read (if any) is ended (so the handle may
37 // become readable again) but no data is "removed" from the data pipe. 35 // become readable again) but no data is "removed" from the data pipe.
38 EndReadData(numBytesRead int) MojoResult 36 EndReadData(numBytesRead int) MojoResult
39 } 37 }
40 38
41 // ProducerHandle is a handle for the producer part of a data pipe. 39 // ProducerHandle is a handle for the producer part of a data pipe.
42 type ProducerHandle interface { 40 type ProducerHandle interface {
43 Handle 41 Handle
44 42
45 // WriteData writes data to the data pipe producer handle with the 43 // WriteData writes data to the data pipe producer handle with the
46 // given flags. On success, returns the number of bytes that were 44 // given flags. On success, returns the number of bytes that were
47 // actually written. 45 // actually written.
48 WriteData(data []byte, flags MojoWriteDataFlags) (MojoResult, int) 46 WriteData(data []byte, flags MojoWriteDataFlags) (MojoResult, int)
49 47
50 // BeginWriteData begins a two-phase write to the data pipe producer. 48 // BeginWriteData begins a two-phase write to the data pipe producer.
51 » // On success, returns a slice to which the caller can write. If flags 49 » // On success, returns a slice to which the caller can write. The slice
52 » // has |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, then the slice length will 50 » // length will always be a multiple of the element size.
53 » // be at least as large as |numBytes|, which must also be a multiple of
54 » // the element size (otherwise the caller must check the length of the
55 » // slice).
56 // 51 //
57 // During a two-phase write, this handle is *not* writable. E.g., write 52 // During a two-phase write, this handle is *not* writable. E.g., write
58 // to this handle will return |MOJO_RESULT_BUSY|. 53 // to this handle will return |MOJO_RESULT_BUSY|.
59 // 54 //
60 // Once the caller has finished writing data to the buffer, it should 55 // Once the caller has finished writing data to the buffer, it should
61 // call |EndWriteData()| to specify the amount written and to complete 56 // call |EndWriteData()| to specify the amount written and to complete
62 // the two-phase write. 57 // the two-phase write.
63 » BeginWriteData(numBytes int, flags MojoWriteDataFlags) (MojoResult, []by te) 58 » BeginWriteData(flags MojoWriteDataFlags) (MojoResult, []byte)
64 59
65 // EndWriteData ends a two-phase write to the data pipe producer that 60 // EndWriteData ends a two-phase write to the data pipe producer that
66 // was begun by a call to |BeginWriteData()| on the same handle. 61 // was begun by a call to |BeginWriteData()| on the same handle.
67 // |numBytesWritten| should indicate the amount of data actually 62 // |numBytesWritten| should indicate the amount of data actually
68 // written; it must be less than or equal to the length of the slice 63 // written; it must be less than or equal to the length of the slice
69 // returned by |BeginWriteData()| and must be a multiple of the element 64 // returned by |BeginWriteData()| and must be a multiple of the element
70 // size. The slice returned from |BeginWriteData()| must have been 65 // size. The slice returned from |BeginWriteData()| must have been
71 // filled with exactly |numBytesWritten| bytes of data. 66 // filled with exactly |numBytesWritten| bytes of data.
72 // 67 //
73 // On failure, the two-phase write (if any) is ended (so the handle may 68 // On failure, the two-phase write (if any) is ended (so the handle may
74 // become writable again, if there's space available) but no data 69 // become writable again, if there's space available) but no data
75 // written to the slice is "put into" the data pipe. 70 // written to the slice is "put into" the data pipe.
76 EndWriteData(numBytesWritten int) MojoResult 71 EndWriteData(numBytesWritten int) MojoResult
77 } 72 }
78 73
79 type dataPipeConsumer struct { 74 type dataPipeConsumer struct {
80 // baseHandle should always be the first component of this struct, 75 // baseHandle should always be the first component of this struct,
81 // see |finalizeHandle()| for more details. 76 // see |finalizeHandle()| for more details.
82 baseHandle 77 baseHandle
83 } 78 }
84 79
85 func (h *dataPipeConsumer) ReadData(flags MojoReadDataFlags) (MojoResult, []byte ) { 80 func (h *dataPipeConsumer) ReadData(flags MojoReadDataFlags) (MojoResult, []byte ) {
86 h.core.mu.Lock() 81 h.core.mu.Lock()
87 r, buf := sysImpl.ReadData(uint32(h.mojoHandle), uint32(flags)) 82 r, buf := sysImpl.ReadData(uint32(h.mojoHandle), uint32(flags))
88 h.core.mu.Unlock() 83 h.core.mu.Unlock()
89 return MojoResult(r), buf 84 return MojoResult(r), buf
90 } 85 }
91 86
92 func (h *dataPipeConsumer) BeginReadData(numBytes int, flags MojoReadDataFlags) (MojoResult, []byte) { 87 func (h *dataPipeConsumer) BeginReadData(flags MojoReadDataFlags) (MojoResult, [ ]byte) {
93 h.core.mu.Lock() 88 h.core.mu.Lock()
94 » r, buf := sysImpl.BeginReadData(uint32(h.mojoHandle), uint32(numBytes), uint32(flags)) 89 » r, buf := sysImpl.BeginReadData(uint32(h.mojoHandle), uint32(flags))
95 h.core.mu.Unlock() 90 h.core.mu.Unlock()
96 return MojoResult(r), buf 91 return MojoResult(r), buf
97 } 92 }
98 93
99 func (h *dataPipeConsumer) EndReadData(numBytesRead int) MojoResult { 94 func (h *dataPipeConsumer) EndReadData(numBytesRead int) MojoResult {
100 h.core.mu.Lock() 95 h.core.mu.Lock()
101 r := sysImpl.EndReadData(uint32(h.mojoHandle), uint32(numBytesRead)) 96 r := sysImpl.EndReadData(uint32(h.mojoHandle), uint32(numBytesRead))
102 h.core.mu.Unlock() 97 h.core.mu.Unlock()
103 return MojoResult(r) 98 return MojoResult(r)
104 } 99 }
105 100
106 type dataPipeProducer struct { 101 type dataPipeProducer struct {
107 // baseHandle should always be the first component of this struct, 102 // baseHandle should always be the first component of this struct,
108 // see |finalizeHandle()| for more details. 103 // see |finalizeHandle()| for more details.
109 baseHandle 104 baseHandle
110 } 105 }
111 106
112 func (h *dataPipeProducer) WriteData(data []byte, flags MojoWriteDataFlags) (Moj oResult, int) { 107 func (h *dataPipeProducer) WriteData(data []byte, flags MojoWriteDataFlags) (Moj oResult, int) {
113 h.core.mu.Lock() 108 h.core.mu.Lock()
114 r, bytesWritten := sysImpl.WriteData(uint32(h.mojoHandle), data, uint32( flags)) 109 r, bytesWritten := sysImpl.WriteData(uint32(h.mojoHandle), data, uint32( flags))
115 h.core.mu.Unlock() 110 h.core.mu.Unlock()
116 return MojoResult(r), int(bytesWritten) 111 return MojoResult(r), int(bytesWritten)
117 } 112 }
118 113
119 func (h *dataPipeProducer) BeginWriteData(numBytes int, flags MojoWriteDataFlags ) (MojoResult, []byte) { 114 func (h *dataPipeProducer) BeginWriteData(flags MojoWriteDataFlags) (MojoResult, []byte) {
120 h.core.mu.Lock() 115 h.core.mu.Lock()
121 » r, buf := sysImpl.BeginWriteData(uint32(h.mojoHandle), uint32(numBytes), uint32(flags)) 116 » r, buf := sysImpl.BeginWriteData(uint32(h.mojoHandle), uint32(flags))
122 h.core.mu.Unlock() 117 h.core.mu.Unlock()
123 return MojoResult(r), buf 118 return MojoResult(r), buf
124 } 119 }
125 120
126 func (h *dataPipeProducer) EndWriteData(numBytesWritten int) MojoResult { 121 func (h *dataPipeProducer) EndWriteData(numBytesWritten int) MojoResult {
127 h.core.mu.Lock() 122 h.core.mu.Lock()
128 r := sysImpl.EndWriteData(uint32(h.mojoHandle), uint32(numBytesWritten)) 123 r := sysImpl.EndWriteData(uint32(h.mojoHandle), uint32(numBytesWritten))
129 h.core.mu.Unlock() 124 h.core.mu.Unlock()
130 return MojoResult(r) 125 return MojoResult(r)
131 } 126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698