| 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 InputStream { | 5 class _SocketInputStream implements InputStream { |
| 6 _SocketInputStream(Socket socket) : _socket = socket { | 6 _SocketInputStream(Socket socket) : _socket = socket { |
| 7 if (_socket._closed) _closed = true; | 7 if (_socket._closed) _closed = true; |
| 8 _socket.onClosed = _onClosed; | 8 _socket.onClosed = _onClosed; |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 _socket._closeWrite(); | 100 _socket._closeWrite(); |
| 101 _closed = true; | 101 _closed = true; |
| 102 // Invoke the callback asynchronously. | 102 // Invoke the callback asynchronously. |
| 103 new Timer(0, (t) { | 103 new Timer(0, (t) { |
| 104 if (_onClosed != null) _onClosed(); | 104 if (_onClosed != null) _onClosed(); |
| 105 }); | 105 }); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 | 108 |
| 109 void destroy() { | 109 void destroy() { |
| 110 _socket.onWrite = null; | 110 _socket._onWrite = null; |
| 111 _pendingWrites.clear(); | 111 _pendingWrites.clear(); |
| 112 _socket.close(); | 112 _socket.close(); |
| 113 _closed = true; | 113 _closed = true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 bool get closed => _closed; | 116 bool get closed => _closed; |
| 117 | 117 |
| 118 void set onNoPendingWrites(void callback()) { | 118 void set onNoPendingWrites(void callback()) { |
| 119 _onNoPendingWrites = callback; | 119 _onNoPendingWrites = callback; |
| 120 if (_onNoPendingWrites != null) { | 120 if (_onNoPendingWrites != null) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if (_onNoPendingWrites != null) _onNoPendingWrites(); | 182 if (_onNoPendingWrites != null) _onNoPendingWrites(); |
| 183 } | 183 } |
| 184 if (_onNoPendingWrites == null) { | 184 if (_onNoPendingWrites == null) { |
| 185 _socket._onWrite = null; | 185 _socket._onWrite = null; |
| 186 } else { | 186 } else { |
| 187 _socket._onWrite = _onWrite; | 187 _socket._onWrite = _onWrite; |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 bool _onSocketError(e) { | 191 bool _onSocketError(e) { |
| 192 close(); | 192 destroy(); |
| 193 if (_onError != null) { | 193 if (_onError != null) { |
| 194 _onError(e); | 194 _onError(e); |
| 195 return true; | 195 return true; |
| 196 } else { | 196 } else { |
| 197 return false; | 197 throw e; |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 | 200 |
| 201 Socket _socket; | 201 Socket _socket; |
| 202 _BufferList _pendingWrites; | 202 _BufferList _pendingWrites; |
| 203 Function _onNoPendingWrites; | 203 Function _onNoPendingWrites; |
| 204 Function _onClosed; | 204 Function _onClosed; |
| 205 bool _closing = false; | 205 bool _closing = false; |
| 206 bool _closed = false; | 206 bool _closed = false; |
| 207 } | 207 } |
| OLD | NEW |