| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 InputStream { | 5 class SocketInputStream implements InputStream { |
| 6 SocketInputStream(Socket socket) { | 6 SocketInputStream(Socket socket) { |
| 7 _socket = socket; | 7 _socket = socket; |
| 8 } | 8 } |
| 9 | 9 |
| 10 List<int> read([int len]) { | 10 List<int> read([int len]) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (bytesWritten == len) return true; | 158 if (bytesWritten == len) return true; |
| 159 } | 159 } |
| 160 | 160 |
| 161 // Place remaining data on the pending writes queue. | 161 // Place remaining data on the pending writes queue. |
| 162 int notWrittenOffset = offset + bytesWritten; | 162 int notWrittenOffset = offset + bytesWritten; |
| 163 if (copyBuffer) { | 163 if (copyBuffer) { |
| 164 List<int> newBuffer = | 164 List<int> newBuffer = |
| 165 buffer.getRange(notWrittenOffset, len - bytesWritten); | 165 buffer.getRange(notWrittenOffset, len - bytesWritten); |
| 166 _pendingWrites.add(newBuffer); | 166 _pendingWrites.add(newBuffer); |
| 167 } else { | 167 } else { |
| 168 assert(offset + len = buffer.length); | 168 assert(offset + len == buffer.length); |
| 169 _pendingWrites.add(buffer, notWrittenOffset); | 169 _pendingWrites.add(buffer, notWrittenOffset); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 | 172 |
| 173 void _writeHandler() { | 173 void _writeHandler() { |
| 174 // Write as much buffered data to the socket as possible. | 174 // Write as much buffered data to the socket as possible. |
| 175 while (!_pendingWrites.isEmpty()) { | 175 while (!_pendingWrites.isEmpty()) { |
| 176 List<int> buffer = _pendingWrites.first; | 176 List<int> buffer = _pendingWrites.first; |
| 177 int offset = _pendingWrites.index; | 177 int offset = _pendingWrites.index; |
| 178 int bytesToWrite = buffer.length - offset; | 178 int bytesToWrite = buffer.length - offset; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 198 if (_streamErrorHandler != null) _streamErrorHandler(); | 198 if (_streamErrorHandler != null) _streamErrorHandler(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 Socket _socket; | 201 Socket _socket; |
| 202 _BufferList2 _pendingWrites; | 202 _BufferList2 _pendingWrites; |
| 203 var _noPendingWriteHandler; | 203 var _noPendingWriteHandler; |
| 204 var _streamErrorHandler; | 204 var _streamErrorHandler; |
| 205 bool _closing = false; | 205 bool _closing = false; |
| 206 bool _closed = false; | 206 bool _closed = false; |
| 207 } | 207 } |
| OLD | NEW |