| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 bool writeFrom(List<int> buffer, [int offset = 0, int len]) { | 83 bool writeFrom(List<int> buffer, [int offset = 0, int len]) { |
| 84 return _write( | 84 return _write( |
| 85 buffer, offset, (len == null) ? buffer.length - offset : len, true); | 85 buffer, offset, (len == null) ? buffer.length - offset : len, true); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void flush() { | 88 void flush() { |
| 89 // Nothing to do on a socket output stream. | 89 // Nothing to do on a socket output stream. |
| 90 } | 90 } |
| 91 | 91 |
| 92 void close() { | 92 void close() { |
| 93 if (_closing && _closed) return; | 93 if (_closing) return; |
| 94 _closing = true; |
| 94 if (!_pendingWrites.isEmpty) { | 95 if (!_pendingWrites.isEmpty) { |
| 95 // Mark the socket for close when all data is written. | 96 // Mark the socket for close when all data is written. |
| 96 _closing = true; | |
| 97 _socket._onWrite = _onWrite; | 97 _socket._onWrite = _onWrite; |
| 98 } else { | 98 } else { |
| 99 // Close the socket for writing. | 99 // Close the socket for writing. |
| 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 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |