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

Side by Side Diff: runtime/bin/socket_stream_impl.dart

Issue 10379018: Revert "Revert "Implement {Int,Uint}{8,16,32,64} and Float{32,64} typed arrays."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class _SocketInputStream implements SocketInputStream { 5 class _SocketInputStream implements SocketInputStream {
6 _SocketInputStream(Socket socket) : _socket = socket { 6 _SocketInputStream(Socket socket) : _socket = socket {
7 if (_socket._id == -1) _closed = true; 7 if (_socket._id == -1) _closed = true;
8 _socket.onClosed = _onClosed; 8 _socket.onClosed = _onClosed;
9 } 9 }
10 10
11 List<int> read([int len]) { 11 List<int> read([int len]) {
12 int bytesToRead = available(); 12 int bytesToRead = available();
13 if (bytesToRead == 0) return null; 13 if (bytesToRead == 0) return null;
14 if (len !== null) { 14 if (len !== null) {
15 if (len <= 0) { 15 if (len <= 0) {
16 throw new StreamException("Illegal length $len"); 16 throw new StreamException("Illegal length $len");
17 } else if (bytesToRead > len) { 17 } else if (bytesToRead > len) {
18 bytesToRead = len; 18 bytesToRead = len;
19 } 19 }
20 } 20 }
21 ByteArray buffer = new ByteArray(bytesToRead); 21 List<int> buffer = new Uint8List(bytesToRead);
22 int bytesRead = _socket.readList(buffer, 0, bytesToRead); 22 int bytesRead = _socket.readList(buffer, 0, bytesToRead);
23 if (bytesRead == 0) { 23 if (bytesRead == 0) {
24 // On MacOS when reading from a tty Ctrl-D will result in one 24 // On MacOS when reading from a tty Ctrl-D will result in one
25 // byte reported as available. Attempting to read it out will 25 // byte reported as available. Attempting to read it out will
26 // result in zero bytes read. When that happens there is no data 26 // result in zero bytes read. When that happens there is no data
27 // which is indicated by a null return value. 27 // which is indicated by a null return value.
28 return null; 28 return null;
29 } else if (bytesRead < bytesToRead) { 29 } else if (bytesRead < bytesToRead) {
30 ByteArray newBuffer = new ByteArray(bytesRead); 30 List<int> newBuffer = new Uint8List(bytesRead);
31 newBuffer.setRange(0, bytesRead, buffer); 31 newBuffer.setRange(0, bytesRead, buffer);
32 return newBuffer; 32 return newBuffer;
33 } else { 33 } else {
34 return buffer; 34 return buffer;
35 } 35 }
36 } 36 }
37 37
38 int readInto(List<int> buffer, [int offset = 0, int len]) { 38 int readInto(List<int> buffer, [int offset = 0, int len]) {
39 if (_closed) return null; 39 if (_closed) return null;
40 if (len === null) len = buffer.length; 40 if (len === null) len = buffer.length;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 208 }
209 } 209 }
210 210
211 Socket _socket; 211 Socket _socket;
212 _BufferList _pendingWrites; 212 _BufferList _pendingWrites;
213 Function _onNoPendingWrites; 213 Function _onNoPendingWrites;
214 Function _onClosed; 214 Function _onClosed;
215 bool _closing = false; 215 bool _closing = false;
216 bool _closed = false; 216 bool _closed = false;
217 } 217 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698