| 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(address, | 6 /* patch */ static Future<RawServerSocket> bind(address, |
| 7 int port, | 7 int port, |
| 8 {int backlog: 0, | 8 {int backlog: 0, |
| 9 bool v6Only: false}) { | 9 bool v6Only: false}) { |
| 10 return _RawServerSocket.bind(address, port, backlog, v6Only); | 10 return _RawServerSocket.bind(address, port, backlog, v6Only); |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 int backlog, | 730 int backlog, |
| 731 bool v6Only) { | 731 bool v6Only) { |
| 732 if (port < 0 || port > 0xFFFF) | 732 if (port < 0 || port > 0xFFFF) |
| 733 throw new ArgumentError("Invalid port $port"); | 733 throw new ArgumentError("Invalid port $port"); |
| 734 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); | 734 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); |
| 735 return _NativeSocket.bind(address, port, backlog, v6Only) | 735 return _NativeSocket.bind(address, port, backlog, v6Only) |
| 736 .then((socket) => new _RawServerSocket(socket)); | 736 .then((socket) => new _RawServerSocket(socket)); |
| 737 } | 737 } |
| 738 | 738 |
| 739 _RawServerSocket(this._socket) { | 739 _RawServerSocket(this._socket) { |
| 740 var zone = Zone.current; |
| 740 _controller = new StreamController(sync: true, | 741 _controller = new StreamController(sync: true, |
| 741 onListen: _onSubscriptionStateChange, | 742 onListen: _onSubscriptionStateChange, |
| 742 onCancel: _onSubscriptionStateChange, | 743 onCancel: _onSubscriptionStateChange, |
| 743 onPause: _onPauseStateChange, | 744 onPause: _onPauseStateChange, |
| 744 onResume: _onPauseStateChange); | 745 onResume: _onPauseStateChange); |
| 745 _socket.closeFuture.then((_) => _controller.close()); | 746 _socket.closeFuture.then((_) => _controller.close()); |
| 746 _socket.setHandlers( | 747 _socket.setHandlers( |
| 747 read: () { | 748 read: zone.bindCallback(() { |
| 748 var socket = _socket.accept(); | 749 var socket = _socket.accept(); |
| 749 if (socket != null) _controller.add(new _RawSocket(socket)); | 750 if (socket != null) _controller.add(new _RawSocket(socket)); |
| 750 }, | 751 }), |
| 751 error: (e) { | 752 error: zone.bindUnaryCallback((e) { |
| 752 _controller.addError(e); | 753 _controller.addError(e); |
| 753 _controller.close(); | 754 _controller.close(); |
| 754 } | 755 }) |
| 755 ); | 756 ); |
| 756 } | 757 } |
| 757 | 758 |
| 758 StreamSubscription<RawSocket> listen(void onData(RawSocket event), | 759 StreamSubscription<RawSocket> listen(void onData(RawSocket event), |
| 759 {Function onError, | 760 {Function onError, |
| 760 void onDone(), | 761 void onDone(), |
| 761 bool cancelOnError}) { | 762 bool cancelOnError}) { |
| 762 return _controller.stream.listen( | 763 return _controller.stream.listen( |
| 763 onData, | 764 onData, |
| 764 onError: onError, | 765 onError: onError, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 | 808 |
| 808 // Flag to handle Ctrl-D closing of stdio on Mac OS. | 809 // Flag to handle Ctrl-D closing of stdio on Mac OS. |
| 809 bool _isMacOSTerminalInput = false; | 810 bool _isMacOSTerminalInput = false; |
| 810 | 811 |
| 811 static Future<RawSocket> connect(host, int port) { | 812 static Future<RawSocket> connect(host, int port) { |
| 812 return _NativeSocket.connect(host, port) | 813 return _NativeSocket.connect(host, port) |
| 813 .then((socket) => new _RawSocket(socket)); | 814 .then((socket) => new _RawSocket(socket)); |
| 814 } | 815 } |
| 815 | 816 |
| 816 _RawSocket(this._socket) { | 817 _RawSocket(this._socket) { |
| 818 var zone = Zone.current; |
| 817 _controller = new StreamController(sync: true, | 819 _controller = new StreamController(sync: true, |
| 818 onListen: _onSubscriptionStateChange, | 820 onListen: _onSubscriptionStateChange, |
| 819 onCancel: _onSubscriptionStateChange, | 821 onCancel: _onSubscriptionStateChange, |
| 820 onPause: _onPauseStateChange, | 822 onPause: _onPauseStateChange, |
| 821 onResume: _onPauseStateChange); | 823 onResume: _onPauseStateChange); |
| 822 _socket.closeFuture.then((_) => _controller.close()); | 824 _socket.closeFuture.then((_) => _controller.close()); |
| 823 _socket.setHandlers( | 825 _socket.setHandlers( |
| 824 read: () => _controller.add(RawSocketEvent.READ), | 826 read: () => _controller.add(RawSocketEvent.READ), |
| 825 write: () { | 827 write: () { |
| 826 // The write event handler is automatically disabled by the | 828 // The write event handler is automatically disabled by the |
| 827 // event handler when it fires. | 829 // event handler when it fires. |
| 828 _writeEventsEnabled = false; | 830 _writeEventsEnabled = false; |
| 829 _controller.add(RawSocketEvent.WRITE); | 831 _controller.add(RawSocketEvent.WRITE); |
| 830 }, | 832 }, |
| 831 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), | 833 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), |
| 832 destroyed: () => _controller.add(RawSocketEvent.CLOSED), | 834 destroyed: () => _controller.add(RawSocketEvent.CLOSED), |
| 833 error: (e) { | 835 error: zone.bindUnaryCallback((e) { |
| 834 _controller.addError(e); | 836 _controller.addError(e); |
| 835 close(); | 837 close(); |
| 836 } | 838 }) |
| 837 ); | 839 ); |
| 838 } | 840 } |
| 839 | 841 |
| 840 factory _RawSocket._writePipe(int fd) { | 842 factory _RawSocket._writePipe(int fd) { |
| 841 var native = new _NativeSocket.pipe(); | 843 var native = new _NativeSocket.pipe(); |
| 842 native.isClosedRead = true; | 844 native.isClosedRead = true; |
| 843 if (fd != null) _getStdioHandle(native, fd); | 845 if (fd != null) _getStdioHandle(native, fd); |
| 844 return new _RawSocket(native); | 846 return new _RawSocket(native); |
| 845 } | 847 } |
| 846 | 848 |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 if (_detachReady != null) { | 1274 if (_detachReady != null) { |
| 1273 _detachReady.complete(null); | 1275 _detachReady.complete(null); |
| 1274 } else { | 1276 } else { |
| 1275 if (_raw != null) { | 1277 if (_raw != null) { |
| 1276 _raw.shutdown(SocketDirection.SEND); | 1278 _raw.shutdown(SocketDirection.SEND); |
| 1277 _disableWriteEvent(); | 1279 _disableWriteEvent(); |
| 1278 } | 1280 } |
| 1279 } | 1281 } |
| 1280 } | 1282 } |
| 1281 } | 1283 } |
| OLD | NEW |