| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 void set onData(void callback()) { | 60 void set onData(void callback()) { |
| 61 _socket._onData = callback; | 61 _socket._onData = callback; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void set onClosed(void callback()) { | 64 void set onClosed(void callback()) { |
| 65 _clientCloseHandler = callback; | 65 _clientCloseHandler = callback; |
| 66 _socket._onClosed = _onClosed; | 66 _socket._onClosed = _onClosed; |
| 67 } | 67 } |
| 68 | 68 |
| 69 void set onError(void callback(e)) { |
| 70 _onError = callback; |
| 71 } |
| 72 |
| 69 void _onClosed() { | 73 void _onClosed() { |
| 70 _closed = true; | 74 _closed = true; |
| 71 if (_clientCloseHandler !== null) { | 75 if (_clientCloseHandler !== null) { |
| 72 _clientCloseHandler(); | 76 _clientCloseHandler(); |
| 73 } | 77 } |
| 74 } | 78 } |
| 75 | 79 |
| 76 void set onError(void callback(Exception e)) { | 80 void _onSocketError(e) { |
| 77 _errorCallback = callback; | |
| 78 } | |
| 79 | |
| 80 void _onError(Exception e) { | |
| 81 close(); | 81 close(); |
| 82 if (_errorCallback != null) _errorCallback(e); | 82 if (_onError != null) { |
| 83 _onError(e); |
| 84 return true; |
| 85 } else { |
| 86 return false; |
| 87 } |
| 83 } | 88 } |
| 84 | 89 |
| 85 Socket _socket; | 90 Socket _socket; |
| 86 bool _closed = false; | 91 bool _closed = false; |
| 87 Function _clientCloseHandler; | 92 Function _clientCloseHandler; |
| 88 Function _errorCallback; | 93 Function _onError; |
| 89 } | 94 } |
| 90 | 95 |
| 91 | 96 |
| 92 class _SocketOutputStream | 97 class _SocketOutputStream |
| 93 extends _BaseOutputStream implements SocketOutputStream { | 98 extends _BaseOutputStream implements SocketOutputStream { |
| 94 _SocketOutputStream(Socket socket) | 99 _SocketOutputStream(Socket socket) |
| 95 : _socket = socket, _pendingWrites = new _BufferList(); | 100 : _socket = socket, _pendingWrites = new _BufferList(); |
| 96 | 101 |
| 97 bool write(List<int> buffer, [bool copyBuffer = true]) { | 102 bool write(List<int> buffer, [bool copyBuffer = true]) { |
| 98 return _write(buffer, 0, buffer.length, copyBuffer); | 103 return _write(buffer, 0, buffer.length, copyBuffer); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } else { | 179 } else { |
| 175 if (_onNoPendingWrites != null) _onNoPendingWrites(); | 180 if (_onNoPendingWrites != null) _onNoPendingWrites(); |
| 176 } | 181 } |
| 177 if (_onNoPendingWrites == null) { | 182 if (_onNoPendingWrites == null) { |
| 178 _socket._onWrite = null; | 183 _socket._onWrite = null; |
| 179 } else { | 184 } else { |
| 180 _socket._onWrite = _onWrite; | 185 _socket._onWrite = _onWrite; |
| 181 } | 186 } |
| 182 } | 187 } |
| 183 | 188 |
| 184 void set onError(void callback(Exception e)) { | 189 bool _onSocketError(e) { |
| 185 _errorCallback = callback; | |
| 186 } | |
| 187 | |
| 188 void _onError(Exception e) { | |
| 189 close(); | 190 close(); |
| 190 if (_errorCallback != null) _errorCallback(e); | 191 if (_onError != null) { |
| 192 _onError(e); |
| 193 return true; |
| 194 } else { |
| 195 return false; |
| 196 } |
| 191 } | 197 } |
| 192 | 198 |
| 193 Socket _socket; | 199 Socket _socket; |
| 194 _BufferList _pendingWrites; | 200 _BufferList _pendingWrites; |
| 195 var _onNoPendingWrites; | 201 var _onNoPendingWrites; |
| 196 Function _errorCallback; | |
| 197 bool _closing = false; | 202 bool _closing = false; |
| 198 bool _closed = false; | 203 bool _closed = false; |
| 199 } | 204 } |
| OLD | NEW |