| 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 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 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 _socket._onWrite = _onWrite; | 172 _socket._onWrite = _onWrite; |
| 173 return false; | 173 return false; |
| 174 } | 174 } |
| 175 | 175 |
| 176 void _onWrite() { | 176 void _onWrite() { |
| 177 // Write as much buffered data to the socket as possible. | 177 // Write as much buffered data to the socket as possible. |
| 178 while (!_pendingWrites.isEmpty()) { | 178 while (!_pendingWrites.isEmpty()) { |
| 179 List<int> buffer = _pendingWrites.first; | 179 List<int> buffer = _pendingWrites.first; |
| 180 int offset = _pendingWrites.index; | 180 int offset = _pendingWrites.index; |
| 181 int bytesToWrite = buffer.length - offset; | 181 int bytesToWrite = buffer.length - offset; |
| 182 int bytesWritten = _socket.writeList(buffer, offset, bytesToWrite); | 182 int bytesWritten; |
| 183 try { |
| 184 bytesWritten = _socket.writeList(buffer, offset, bytesToWrite); |
| 185 } catch (e) { |
| 186 _pendingWrites.clear(); |
| 187 _onSocketError(e); |
| 188 return; |
| 189 } |
| 183 _pendingWrites.removeBytes(bytesWritten); | 190 _pendingWrites.removeBytes(bytesWritten); |
| 184 if (bytesWritten < bytesToWrite) { | 191 if (bytesWritten < bytesToWrite) { |
| 185 _socket._onWrite = _onWrite; | 192 _socket._onWrite = _onWrite; |
| 186 return; | 193 return; |
| 187 } | 194 } |
| 188 } | 195 } |
| 189 | 196 |
| 190 // All buffered data was written. | 197 // All buffered data was written. |
| 191 if (_closing) { | 198 if (_closing) { |
| 192 _socket._closeWrite(); | 199 _socket._closeWrite(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 214 } | 221 } |
| 215 } | 222 } |
| 216 | 223 |
| 217 Socket _socket; | 224 Socket _socket; |
| 218 _BufferList _pendingWrites; | 225 _BufferList _pendingWrites; |
| 219 Function _onNoPendingWrites; | 226 Function _onNoPendingWrites; |
| 220 Function _onClosed; | 227 Function _onClosed; |
| 221 bool _closing = false; | 228 bool _closing = false; |
| 222 bool _closed = false; | 229 bool _closed = false; |
| 223 } | 230 } |
| OLD | NEW |