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