OLD | NEW |
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 _socket.closeHandler = _closeHandler; | 7 _socket.closeHandler = _closeHandler; |
8 } | 8 } |
9 | 9 |
10 List<int> read([int len]) { | 10 List<int> read([int len]) { |
11 int bytesToRead = available(); | 11 int bytesToRead = available(); |
12 if (bytesToRead == 0) return null; | 12 if (bytesToRead == 0) return null; |
13 if (len !== null) { | 13 if (len !== null) { |
14 if (len <= 0) { | 14 if (len <= 0) { |
15 throw new StreamException("Illegal length $len"); | 15 throw new StreamException("Illegal length $len"); |
16 } else if (bytesToRead > len) { | 16 } else if (bytesToRead > len) { |
17 bytesToRead = len; | 17 bytesToRead = len; |
18 } | 18 } |
19 } | 19 } |
20 List<int> buffer = new List<int>(bytesToRead); | 20 ByteArray buffer = new ByteArray(bytesToRead); |
21 int bytesRead = _socket.readList(buffer, 0, bytesToRead); | 21 int bytesRead = _socket.readList(buffer, 0, bytesToRead); |
22 if (bytesRead < bytesToRead) { | 22 if (bytesRead < bytesToRead) { |
23 List<int> newBuffer = new List<int>(bytesRead); | 23 ByteArray newBuffer = new ByteArray(bytesRead); |
24 newBuffer.copyFrom(buffer, 0, 0, bytesRead); | 24 newBuffer.setRange(0, bytesRead, buffer); |
25 return newBuffer; | 25 return newBuffer; |
26 } else { | 26 } else { |
27 return buffer; | 27 return buffer; |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 int readInto(List<int> buffer, int offset, int len) { | 31 int readInto(List<int> buffer, int offset, int len) { |
32 if (offset === null) offset = 0; | 32 if (offset === null) offset = 0; |
33 if (len === null) len = buffer.length; | 33 if (len === null) len = buffer.length; |
34 if (offset < 0) throw new StreamException("Illegal offset $offset"); | 34 if (offset < 0) throw new StreamException("Illegal offset $offset"); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (_streamErrorHandler != null) _streamErrorHandler(); | 180 if (_streamErrorHandler != null) _streamErrorHandler(); |
181 } | 181 } |
182 | 182 |
183 Socket _socket; | 183 Socket _socket; |
184 _BufferList _pendingWrites; | 184 _BufferList _pendingWrites; |
185 var _noPendingWriteHandler; | 185 var _noPendingWriteHandler; |
186 var _streamErrorHandler; | 186 var _streamErrorHandler; |
187 bool _closing = false; | 187 bool _closing = false; |
188 bool _closed = false; | 188 bool _closed = false; |
189 } | 189 } |
OLD | NEW |