| 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 | 5 @patch |
| 6 class RawServerSocket { | 6 class RawServerSocket { |
| 7 @patch | 7 @patch |
| 8 static Future<RawServerSocket> bind(address, int port, | 8 static Future<RawServerSocket> bind(address, int port, |
| 9 {int backlog: 0, bool v6Only: false, bool shared: false}) { | 9 {int backlog: 0, bool v6Only: false, bool shared: false}) { |
| 10 return _RawServerSocket.bind(address, port, backlog, v6Only, shared); | 10 return _RawServerSocket.bind(address, port, backlog, v6Only, shared); |
| (...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 if (_controller != null) { | 1129 if (_controller != null) { |
| 1130 throw new StateError("Stream was already listened to"); | 1130 throw new StateError("Stream was already listened to"); |
| 1131 } | 1131 } |
| 1132 var zone = Zone.current; | 1132 var zone = Zone.current; |
| 1133 _controller = new StreamController( | 1133 _controller = new StreamController( |
| 1134 sync: true, | 1134 sync: true, |
| 1135 onListen: _onSubscriptionStateChange, | 1135 onListen: _onSubscriptionStateChange, |
| 1136 onCancel: _onSubscriptionStateChange, | 1136 onCancel: _onSubscriptionStateChange, |
| 1137 onPause: _onPauseStateChange, | 1137 onPause: _onPauseStateChange, |
| 1138 onResume: _onPauseStateChange); | 1138 onResume: _onPauseStateChange); |
| 1139 _socket.setHandlers(read: zone.bindCallback(() { | 1139 _socket.setHandlers(read: zone.bindCallbackGuarded(() { |
| 1140 while (_socket.available > 0) { | 1140 while (_socket.available > 0) { |
| 1141 var socket = _socket.accept(); | 1141 var socket = _socket.accept(); |
| 1142 if (socket == null) return; | 1142 if (socket == null) return; |
| 1143 _controller.add(new _RawSocket(socket)); | 1143 _controller.add(new _RawSocket(socket)); |
| 1144 if (_controller.isPaused) return; | 1144 if (_controller.isPaused) return; |
| 1145 } | 1145 } |
| 1146 }), error: zone.bindUnaryCallback((e) { | 1146 }), error: zone.bindUnaryCallbackGuarded((e) { |
| 1147 _controller.addError(e); | 1147 _controller.addError(e); |
| 1148 _controller.close(); | 1148 _controller.close(); |
| 1149 }), destroyed: () { | 1149 }), destroyed: () { |
| 1150 _controller.close(); | 1150 _controller.close(); |
| 1151 if (_referencePort != null) { | 1151 if (_referencePort != null) { |
| 1152 _referencePort.close(); | 1152 _referencePort.close(); |
| 1153 _referencePort = null; | 1153 _referencePort = null; |
| 1154 } | 1154 } |
| 1155 }); | 1155 }); |
| 1156 return _controller.stream.listen(onData, | 1156 return _controller.stream.listen(onData, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 // The write event handler is automatically disabled by the | 1230 // The write event handler is automatically disabled by the |
| 1231 // event handler when it fires. | 1231 // event handler when it fires. |
| 1232 writeEventsEnabled = false; | 1232 writeEventsEnabled = false; |
| 1233 _controller.add(RawSocketEvent.WRITE); | 1233 _controller.add(RawSocketEvent.WRITE); |
| 1234 }, | 1234 }, |
| 1235 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), | 1235 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), |
| 1236 destroyed: () { | 1236 destroyed: () { |
| 1237 _controller.add(RawSocketEvent.CLOSED); | 1237 _controller.add(RawSocketEvent.CLOSED); |
| 1238 _controller.close(); | 1238 _controller.close(); |
| 1239 }, | 1239 }, |
| 1240 error: zone.bindUnaryCallback((e) { | 1240 error: zone.bindUnaryCallbackGuarded((e) { |
| 1241 _controller.addError(e); | 1241 _controller.addError(e); |
| 1242 _socket.close(); | 1242 _socket.close(); |
| 1243 })); | 1243 })); |
| 1244 } | 1244 } |
| 1245 | 1245 |
| 1246 factory _RawSocket._writePipe() { | 1246 factory _RawSocket._writePipe() { |
| 1247 var native = new _NativeSocket.pipe(); | 1247 var native = new _NativeSocket.pipe(); |
| 1248 native.isClosedRead = true; | 1248 native.isClosedRead = true; |
| 1249 native.closedReadEventSent = true; | 1249 native.closedReadEventSent = true; |
| 1250 return new _RawSocket(native); | 1250 return new _RawSocket(native); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1727 // The write event handler is automatically disabled by the | 1727 // The write event handler is automatically disabled by the |
| 1728 // event handler when it fires. | 1728 // event handler when it fires. |
| 1729 writeEventsEnabled = false; | 1729 writeEventsEnabled = false; |
| 1730 _controller.add(RawSocketEvent.WRITE); | 1730 _controller.add(RawSocketEvent.WRITE); |
| 1731 }, | 1731 }, |
| 1732 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), | 1732 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), |
| 1733 destroyed: () { | 1733 destroyed: () { |
| 1734 _controller.add(RawSocketEvent.CLOSED); | 1734 _controller.add(RawSocketEvent.CLOSED); |
| 1735 _controller.close(); | 1735 _controller.close(); |
| 1736 }, | 1736 }, |
| 1737 error: zone.bindUnaryCallback((e) { | 1737 error: zone.bindUnaryCallbackGuarded((e) { |
| 1738 _controller.addError(e); | 1738 _controller.addError(e); |
| 1739 _socket.close(); | 1739 _socket.close(); |
| 1740 })); | 1740 })); |
| 1741 } | 1741 } |
| 1742 | 1742 |
| 1743 static Future<RawDatagramSocket> bind(host, int port, bool reuseAddress) { | 1743 static Future<RawDatagramSocket> bind(host, int port, bool reuseAddress) { |
| 1744 _throwOnBadPort(port); | 1744 _throwOnBadPort(port); |
| 1745 return _NativeSocket | 1745 return _NativeSocket |
| 1746 .bindDatagram(host, port, reuseAddress) | 1746 .bindDatagram(host, port, reuseAddress) |
| 1747 .then((socket) => new _RawDatagramSocket(socket)); | 1747 .then((socket) => new _RawDatagramSocket(socket)); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 } else { | 1829 } else { |
| 1830 _socket.close(); | 1830 _socket.close(); |
| 1831 } | 1831 } |
| 1832 } | 1832 } |
| 1833 } | 1833 } |
| 1834 | 1834 |
| 1835 Datagram _makeDatagram( | 1835 Datagram _makeDatagram( |
| 1836 List<int> data, String address, List<int> in_addr, int port) { | 1836 List<int> data, String address, List<int> in_addr, int port) { |
| 1837 return new Datagram(data, new _InternetAddress(address, null, in_addr), port); | 1837 return new Datagram(data, new _InternetAddress(address, null, in_addr), port); |
| 1838 } | 1838 } |
| OLD | NEW |