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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 if (_closing) return; | 95 if (_closing) return; |
96 _closing = true; | 96 _closing = true; |
97 if (!_pendingWrites.isEmpty) { | 97 if (!_pendingWrites.isEmpty) { |
98 // Mark the socket for close when all data is written. | 98 // Mark the socket for close when all data is written. |
99 _socket._onWrite = _onWrite; | 99 _socket._onWrite = _onWrite; |
100 } else { | 100 } else { |
101 // Close the socket for writing. | 101 // Close the socket for writing. |
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 Timer.run(() { |
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; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 223 } |
224 | 224 |
225 Socket _socket; | 225 Socket _socket; |
226 _BufferList _pendingWrites; | 226 _BufferList _pendingWrites; |
227 Function _onNoPendingWrites; | 227 Function _onNoPendingWrites; |
228 Function _onClosed; | 228 Function _onClosed; |
229 bool _closing = false; | 229 bool _closing = false; |
230 bool _closed = false; | 230 bool _closed = false; |
231 bool _error = false; | 231 bool _error = false; |
232 } | 232 } |
OLD | NEW |