| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 RawSocket _raw; // Set to null when the raw socket is closed. | 758 RawSocket _raw; // Set to null when the raw socket is closed. |
| 755 bool _closed = false; // Set to true when the raw socket is closed. | 759 bool _closed = false; // Set to true when the raw socket is closed. |
| 756 StreamController _controller; | 760 StreamController _controller; |
| 757 bool _controllerClosed = false; | 761 bool _controllerClosed = false; |
| 758 _SocketStreamConsumer _consumer; | 762 _SocketStreamConsumer _consumer; |
| 759 IOSink _sink; | 763 IOSink _sink; |
| 760 var _subscription; | 764 var _subscription; |
| 761 | 765 |
| 762 _Socket(RawSocket this._raw) { | 766 _Socket(RawSocket this._raw) { |
| 763 _controller = new StreamController<List<int>>( | 767 _controller = new StreamController<List<int>>( |
| 764 onSubscriptionStateChange: _onSubscriptionStateChange, | 768 onListen: _onSubscriptionStateChange, |
| 765 onPauseStateChange: _onPauseStateChange); | 769 onCancel: _onSubscriptionStateChange, |
| 770 onPause: _onPauseStateChange, |
| 771 onResume: _onPauseStateChange); |
| 766 _consumer = new _SocketStreamConsumer(this); | 772 _consumer = new _SocketStreamConsumer(this); |
| 767 _sink = new IOSink(_consumer); | 773 _sink = new IOSink(_consumer); |
| 768 | 774 |
| 769 // Disable read events until there is a subscription. | 775 // Disable read events until there is a subscription. |
| 770 _raw.readEventsEnabled = false; | 776 _raw.readEventsEnabled = false; |
| 771 | 777 |
| 772 // Disable write events until the consumer needs it for pending writes. | 778 // Disable write events until the consumer needs it for pending writes. |
| 773 _raw.writeEventsEnabled = false; | 779 _raw.writeEventsEnabled = false; |
| 774 } | 780 } |
| 775 | 781 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 _raw.onBadCertificate = callback; | 947 _raw.onBadCertificate = callback; |
| 942 } | 948 } |
| 943 | 949 |
| 944 X509Certificate get peerCertificate { | 950 X509Certificate get peerCertificate { |
| 945 if (_raw == null) { | 951 if (_raw == null) { |
| 946 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 952 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 947 } | 953 } |
| 948 return _raw.peerCertificate; | 954 return _raw.peerCertificate; |
| 949 } | 955 } |
| 950 } | 956 } |
| OLD | NEW |