| 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 patch class RawServerSocket { | 5 patch class RawServerSocket { |
| 6 /* patch */ static Future<RawServerSocket> bind([String address = "127.0.0.1", | 6 /* patch */ static Future<RawServerSocket> bind([String address = "127.0.0.1", |
| 7 int port = 0, | 7 int port = 0, |
| 8 int backlog = 0]) { | 8 int backlog = 0]) { |
| 9 return _RawServerSocket.bind(address, port, backlog); | 9 return _RawServerSocket.bind(address, port, backlog); |
| 10 } | 10 } |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 int backlog) { | 425 int backlog) { |
| 426 if (port < 0 || port > 0xFFFF) | 426 if (port < 0 || port > 0xFFFF) |
| 427 throw new ArgumentError("Invalid port $port"); | 427 throw new ArgumentError("Invalid port $port"); |
| 428 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); | 428 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); |
| 429 return _NativeSocket.bind(address, port, backlog) | 429 return _NativeSocket.bind(address, port, backlog) |
| 430 .then((socket) => new _RawServerSocket(socket)); | 430 .then((socket) => new _RawServerSocket(socket)); |
| 431 } | 431 } |
| 432 | 432 |
| 433 _RawServerSocket(this._socket) { | 433 _RawServerSocket(this._socket) { |
| 434 _controller = new StreamController( | 434 _controller = new StreamController( |
| 435 onSubscriptionStateChange: _onSubscriptionStateChange, | 435 onListen: _onSubscriptionStateChange, |
| 436 onPauseStateChange: _onPauseStateChange); | 436 onCancel: _onSubscriptionStateChange, |
| 437 onPause: _onPauseStateChange, |
| 438 onResume: _onPauseStateChange); |
| 437 _socket.closeFuture.then((_) => _controller.close()); | 439 _socket.closeFuture.then((_) => _controller.close()); |
| 438 _socket.setHandlers( | 440 _socket.setHandlers( |
| 439 read: () { | 441 read: () { |
| 440 var socket = _socket.accept(); | 442 var socket = _socket.accept(); |
| 441 if (socket != null) _controller.add(new _RawSocket(socket)); | 443 if (socket != null) _controller.add(new _RawSocket(socket)); |
| 442 }, | 444 }, |
| 443 error: (e) { | 445 error: (e) { |
| 444 _controller.addError(new AsyncError(e)); | 446 _controller.addError(new AsyncError(e)); |
| 445 _controller.close(); | 447 _controller.close(); |
| 446 } | 448 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 bool _readEventsEnabled = true; | 496 bool _readEventsEnabled = true; |
| 495 bool _writeEventsEnabled = true; | 497 bool _writeEventsEnabled = true; |
| 496 | 498 |
| 497 static Future<RawSocket> connect(String host, int port) { | 499 static Future<RawSocket> connect(String host, int port) { |
| 498 return _NativeSocket.connect(host, port) | 500 return _NativeSocket.connect(host, port) |
| 499 .then((socket) => new _RawSocket(socket)); | 501 .then((socket) => new _RawSocket(socket)); |
| 500 } | 502 } |
| 501 | 503 |
| 502 _RawSocket(this._socket) { | 504 _RawSocket(this._socket) { |
| 503 _controller = new StreamController( | 505 _controller = new StreamController( |
| 504 onSubscriptionStateChange: _onSubscriptionStateChange, | 506 onListen: _onSubscriptionStateChange, |
| 505 onPauseStateChange: _onPauseStateChange); | 507 onCancel: _onSubscriptionStateChange, |
| 508 onPause: _onPauseStateChange, |
| 509 onResume: _onPauseStateChange); |
| 506 _socket.closeFuture.then((_) => _controller.close()); | 510 _socket.closeFuture.then((_) => _controller.close()); |
| 507 _socket.setHandlers( | 511 _socket.setHandlers( |
| 508 read: () => _controller.add(RawSocketEvent.READ), | 512 read: () => _controller.add(RawSocketEvent.READ), |
| 509 write: () { | 513 write: () { |
| 510 // The write event handler is automatically disabled by the | 514 // The write event handler is automatically disabled by the |
| 511 // event handler when it fires. | 515 // event handler when it fires. |
| 512 _writeEventsEnabled = false; | 516 _writeEventsEnabled = false; |
| 513 _controller.add(RawSocketEvent.WRITE); | 517 _controller.add(RawSocketEvent.WRITE); |
| 514 }, | 518 }, |
| 515 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), | 519 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 bool _closed = false; // Set to true when the raw socket is closed. | 765 bool _closed = false; // Set to true when the raw socket is closed. |
| 762 StreamController _controller; | 766 StreamController _controller; |
| 763 bool _controllerClosed = false; | 767 bool _controllerClosed = false; |
| 764 _SocketStreamConsumer _consumer; | 768 _SocketStreamConsumer _consumer; |
| 765 IOSink<Socket> _sink; | 769 IOSink<Socket> _sink; |
| 766 Completer _doneCompleter; | 770 Completer _doneCompleter; |
| 767 var _subscription; | 771 var _subscription; |
| 768 | 772 |
| 769 _Socket(RawSocket this._raw) { | 773 _Socket(RawSocket this._raw) { |
| 770 _controller = new StreamController<List<int>>( | 774 _controller = new StreamController<List<int>>( |
| 771 onSubscriptionStateChange: _onSubscriptionStateChange, | 775 onListen: _onSubscriptionStateChange, |
| 772 onPauseStateChange: _onPauseStateChange); | 776 onCancel: _onSubscriptionStateChange, |
| 777 onPause: _onPauseStateChange, |
| 778 onResume: _onPauseStateChange); |
| 773 _consumer = new _SocketStreamConsumer(this); | 779 _consumer = new _SocketStreamConsumer(this); |
| 774 _sink = new IOSink(_consumer); | 780 _sink = new IOSink(_consumer); |
| 775 | 781 |
| 776 // Disable read events until there is a subscription. | 782 // Disable read events until there is a subscription. |
| 777 _raw.readEventsEnabled = false; | 783 _raw.readEventsEnabled = false; |
| 778 | 784 |
| 779 // Disable write events until the consumer needs it for pending writes. | 785 // Disable write events until the consumer needs it for pending writes. |
| 780 _raw.writeEventsEnabled = false; | 786 _raw.writeEventsEnabled = false; |
| 781 } | 787 } |
| 782 | 788 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 _raw.onBadCertificate = callback; | 979 _raw.onBadCertificate = callback; |
| 974 } | 980 } |
| 975 | 981 |
| 976 X509Certificate get peerCertificate { | 982 X509Certificate get peerCertificate { |
| 977 if (_raw == null) { | 983 if (_raw == null) { |
| 978 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 984 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 979 } | 985 } |
| 980 return _raw.peerCertificate; | 986 return _raw.peerCertificate; |
| 981 } | 987 } |
| 982 } | 988 } |
| OLD | NEW |