OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 part of core; | 5 part of core; |
6 | 6 |
7 | 7 |
8 class _MojoDataPipeNatives { | 8 class _MojoDataPipeNatives { |
9 static List MojoCreateDataPipe( | 9 static List MojoCreateDataPipe( |
10 int elementBytes, int capacityBytes, int flags) | 10 int elementBytes, int capacityBytes, int flags) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 MojoHandle handle; | 100 MojoHandle handle; |
101 MojoResult status; | 101 MojoResult status; |
102 final int elementBytes; | 102 final int elementBytes; |
103 | 103 |
104 MojoDataPipeConsumer( | 104 MojoDataPipeConsumer( |
105 this.handle, [this.status = MojoResult.OK, this.elementBytes = 1]); | 105 this.handle, [this.status = MojoResult.OK, this.elementBytes = 1]); |
106 | 106 |
107 int read(ByteData data, [int numBytes = -1, int flags = 0]) { | 107 int read(ByteData data, [int numBytes = -1, int flags = 0]) { |
108 if (handle == null) { | 108 if (handle == null) { |
109 status = MojoResult.INVALID_ARGUMENT; | 109 status = MojoResult.INVALID_ARGUMENT; |
110 return status; | 110 return 0; |
111 } | 111 } |
112 | 112 |
113 int data_numBytes = (numBytes == -1) ? data.lengthInBytes : numBytes; | 113 int data_numBytes = (numBytes == -1) ? data.lengthInBytes : numBytes; |
114 List result = _MojoDataPipeNatives.MojoReadData( | 114 List result = _MojoDataPipeNatives.MojoReadData( |
115 handle.h, data, data_numBytes, flags); | 115 handle.h, data, data_numBytes, flags); |
116 if (result == null) { | 116 if (result == null) { |
117 status = MojoResult.INVALID_ARGUMENT; | 117 status = MojoResult.INVALID_ARGUMENT; |
118 return status; | 118 return 0; |
119 } | 119 } |
120 assert((result is List) && (result.length == 2)); | 120 assert((result is List) && (result.length == 2)); |
121 status = new MojoResult(result[0]); | 121 status = new MojoResult(result[0]); |
122 return result[1]; | 122 return result[1]; |
123 } | 123 } |
124 | 124 |
125 ByteData beginRead([int bufferBytes = 0, int flags = 0]) { | 125 ByteData beginRead([int bufferBytes = 0, int flags = 0]) { |
126 if (handle == null) { | 126 if (handle == null) { |
127 status = MojoResult.INVALID_ARGUMENT; | 127 status = MojoResult.INVALID_ARGUMENT; |
128 return null; | 128 return null; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 MojoHandle consumerHandle = new MojoHandle(result[2]); | 182 MojoHandle consumerHandle = new MojoHandle(result[2]); |
183 MojoDataPipe pipe = new MojoDataPipe._internal(); | 183 MojoDataPipe pipe = new MojoDataPipe._internal(); |
184 pipe.producer = new MojoDataPipeProducer( | 184 pipe.producer = new MojoDataPipeProducer( |
185 producerHandle, new MojoResult(result[0]), elementBytes); | 185 producerHandle, new MojoResult(result[0]), elementBytes); |
186 pipe.consumer = new MojoDataPipeConsumer( | 186 pipe.consumer = new MojoDataPipeConsumer( |
187 consumerHandle, new MojoResult(result[0]), elementBytes); | 187 consumerHandle, new MojoResult(result[0]), elementBytes); |
188 pipe.status = new MojoResult(result[0]); | 188 pipe.status = new MojoResult(result[0]); |
189 return pipe; | 189 return pipe; |
190 } | 190 } |
191 } | 191 } |
OLD | NEW |