| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 7 /** |
| 8 * A high-level class for communicating securely over a TCP socket, using | 8 * A high-level class for communicating securely over a TCP socket, using |
| 9 * TLS and SSL. The [SecureSocket] exposes both a [Stream] and an | 9 * TLS and SSL. The [SecureSocket] exposes both a [Stream] and an |
| 10 * [IOSink] interface, making it ideal for using together with | 10 * [IOSink] interface, making it ideal for using together with |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 _status = HANDSHAKE; | 281 _status = HANDSHAKE; |
| 282 _secureHandshake(); | 282 _secureHandshake(); |
| 283 }) | 283 }) |
| 284 .catchError((error) { | 284 .catchError((error) { |
| 285 _handshakeComplete.completeError(error); | 285 _handshakeComplete.completeError(error); |
| 286 _close(); | 286 _close(); |
| 287 }); | 287 }); |
| 288 } | 288 } |
| 289 | 289 |
| 290 StreamSubscription listen(void onData(RawSocketEvent data), | 290 StreamSubscription listen(void onData(RawSocketEvent data), |
| 291 {void onError(AsyncError error), | 291 {void onError(error), |
| 292 void onDone(), | 292 void onDone(), |
| 293 bool unsubscribeOnError}) { | 293 bool unsubscribeOnError}) { |
| 294 if (_writeEventsEnabled) { | 294 if (_writeEventsEnabled) { |
| 295 _writeEventsEnabled = false; | 295 _writeEventsEnabled = false; |
| 296 _controller.add(RawSocketEvent.WRITE); | 296 _controller.add(RawSocketEvent.WRITE); |
| 297 } | 297 } |
| 298 return _stream.listen(onData, | 298 return _stream.listen(onData, |
| 299 onError: onError, | 299 onError: onError, |
| 300 onDone: onDone, | 300 onDone: onDone, |
| 301 unsubscribeOnError: unsubscribeOnError); | 301 unsubscribeOnError: unsubscribeOnError); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 } | 457 } |
| 458 | 458 |
| 459 return result; | 459 return result; |
| 460 } | 460 } |
| 461 | 461 |
| 462 // Write the data to the socket, and flush it as much as possible | 462 // Write the data to the socket, and flush it as much as possible |
| 463 // until it would block. If the write would block, _writeEncryptedData sets | 463 // until it would block. If the write would block, _writeEncryptedData sets |
| 464 // up handlers to flush the pipeline when possible. | 464 // up handlers to flush the pipeline when possible. |
| 465 int write(List<int> data, [int offset, int bytes]) { | 465 int write(List<int> data, [int offset, int bytes]) { |
| 466 if (_closedWrite) { | 466 if (_closedWrite) { |
| 467 _controller.addError(new AsyncError(new SocketIOException( | 467 _controller.addError(new SocketIOException("Writing to a closed socket")); |
| 468 "Writing to a closed socket"))); | |
| 469 return 0; | 468 return 0; |
| 470 } | 469 } |
| 471 if (_status != CONNECTED) return 0; | 470 if (_status != CONNECTED) return 0; |
| 472 | 471 |
| 473 if (offset == null) offset = 0; | 472 if (offset == null) offset = 0; |
| 474 if (bytes == null) bytes = data.length - offset; | 473 if (bytes == null) bytes = data.length - offset; |
| 475 | 474 |
| 476 var buffer = _secureFilter.buffers[WRITE_PLAINTEXT]; | 475 var buffer = _secureFilter.buffers[WRITE_PLAINTEXT]; |
| 477 if (bytes > buffer.free) { | 476 if (bytes > buffer.free) { |
| 478 bytes = buffer.free; | 477 bytes = buffer.free; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 void _doneHandler() { | 559 void _doneHandler() { |
| 561 if (_filterReadEmpty) { | 560 if (_filterReadEmpty) { |
| 562 _close(); | 561 _close(); |
| 563 } | 562 } |
| 564 } | 563 } |
| 565 | 564 |
| 566 void _errorHandler(e) { | 565 void _errorHandler(e) { |
| 567 _reportError(e, 'Error on underlying RawSocket'); | 566 _reportError(e, 'Error on underlying RawSocket'); |
| 568 } | 567 } |
| 569 | 568 |
| 570 void _reportError(error, String message) { | 569 void _reportError(e, String message) { |
| 571 // TODO(whesse): Call _reportError from all internal functions that throw. | 570 // TODO(whesse): Call _reportError from all internal functions that throw. |
| 572 var e; | 571 if (e is SocketIOException) { |
| 573 if (error is AsyncError) { | |
| 574 e = error; | |
| 575 } else if (error is SocketIOException) { | |
| 576 e = new SocketIOException('$message (${error.message})', error.osError); | 572 e = new SocketIOException('$message (${error.message})', error.osError); |
| 577 } else if (error is OSError) { | 573 } else if (error is OSError) { |
| 578 e = new SocketIOException(message, error); | 574 e = new SocketIOException(message, error); |
| 579 } else { | 575 } else { |
| 580 e = new SocketIOException('$message (${error.toString()})', null); | 576 e = new SocketIOException('$message (${error.toString()})', null); |
| 581 } | 577 } |
| 582 if (_connectPending) { | 578 if (_connectPending) { |
| 583 _handshakeComplete.completeError(e); | 579 _handshakeComplete.completeError(e); |
| 584 } else { | 580 } else { |
| 585 _controller.addError(e); | 581 _controller.addError(e); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 void destroy(); | 753 void destroy(); |
| 758 void handshake(); | 754 void handshake(); |
| 759 void init(); | 755 void init(); |
| 760 X509Certificate get peerCertificate; | 756 X509Certificate get peerCertificate; |
| 761 int processBuffer(int bufferIndex); | 757 int processBuffer(int bufferIndex); |
| 762 void registerBadCertificateCallback(Function callback); | 758 void registerBadCertificateCallback(Function callback); |
| 763 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); | 759 void registerHandshakeCompleteCallback(Function handshakeCompleteHandler); |
| 764 | 760 |
| 765 List<_ExternalBuffer> get buffers; | 761 List<_ExternalBuffer> get buffers; |
| 766 } | 762 } |
| OLD | NEW |