| 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 return _RawServerSocket.bind(address, port, backlog); | 9 bool v6Only: false}) { |
| 10 return _RawServerSocket.bind(address, port, backlog, v6Only); |
| 10 } | 11 } |
| 11 } | 12 } |
| 12 | 13 |
| 13 | 14 |
| 14 patch class RawSocket { | 15 patch class RawSocket { |
| 15 /* patch */ static Future<RawSocket> connect(host, int port) { | 16 /* patch */ static Future<RawSocket> connect(host, int port) { |
| 16 return _RawSocket.connect(host, port); | 17 return _RawSocket.connect(host, port); |
| 17 } | 18 } |
| 18 } | 19 } |
| 19 | 20 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 } | 209 } |
| 209 ); | 210 ); |
| 210 socket.setListening(read: false, write: true); | 211 socket.setListening(read: false, write: true); |
| 211 return completer.future; | 212 return completer.future; |
| 212 } | 213 } |
| 213 }); | 214 }); |
| 214 } | 215 } |
| 215 | 216 |
| 216 static Future<_NativeSocket> bind(host, | 217 static Future<_NativeSocket> bind(host, |
| 217 int port, | 218 int port, |
| 218 int backlog) { | 219 int backlog, |
| 220 bool v6Only) { |
| 219 return new Future.value(host) | 221 return new Future.value(host) |
| 220 .then((host) { | 222 .then((host) { |
| 221 if (host is _InternetAddress) return host; | 223 if (host is _InternetAddress) return host; |
| 222 return lookup(host) | 224 return lookup(host) |
| 223 .then((list) { | 225 .then((list) { |
| 224 if (list.length == 0) { | 226 if (list.length == 0) { |
| 225 throw createError(response, "Failed host name lookup"); | 227 throw createError(response, "Failed host name lookup"); |
| 226 } | 228 } |
| 227 return list[0]; | 229 return list[0]; |
| 228 }); | 230 }); |
| 229 }) | 231 }) |
| 230 .then((address) { | 232 .then((address) { |
| 231 var socket = new _NativeSocket.listen(); | 233 var socket = new _NativeSocket.listen(); |
| 232 socket.address = address; | 234 socket.address = address; |
| 233 var result = socket.nativeCreateBindListen(address._sockaddr_storage, | 235 var result = socket.nativeCreateBindListen(address._sockaddr_storage, |
| 234 port, | 236 port, |
| 235 backlog); | 237 backlog, |
| 238 v6Only); |
| 236 if (result is OSError) { | 239 if (result is OSError) { |
| 237 throw new SocketIOException( | 240 throw new SocketIOException( |
| 238 "Failed to create server socket", result); | 241 "Failed to create server socket", result); |
| 239 } | 242 } |
| 240 if (port != 0) socket.localPort = port; | 243 if (port != 0) socket.localPort = port; |
| 241 return socket; | 244 return socket; |
| 242 }); | 245 }); |
| 243 } | 246 } |
| 244 | 247 |
| 245 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET { | 248 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 if (enabled is! bool) throw new ArgumentError(enabled); | 522 if (enabled is! bool) throw new ArgumentError(enabled); |
| 520 return nativeSetOption(option._value, enabled); | 523 return nativeSetOption(option._value, enabled); |
| 521 } | 524 } |
| 522 | 525 |
| 523 nativeAvailable() native "Socket_Available"; | 526 nativeAvailable() native "Socket_Available"; |
| 524 nativeRead(int len) native "Socket_Read"; | 527 nativeRead(int len) native "Socket_Read"; |
| 525 nativeWrite(List<int> buffer, int offset, int bytes) | 528 nativeWrite(List<int> buffer, int offset, int bytes) |
| 526 native "Socket_WriteList"; | 529 native "Socket_WriteList"; |
| 527 nativeCreateConnect(List<int> addr, | 530 nativeCreateConnect(List<int> addr, |
| 528 int port) native "Socket_CreateConnect"; | 531 int port) native "Socket_CreateConnect"; |
| 529 nativeCreateBindListen(List<int> addr, int port, int backlog) | 532 nativeCreateBindListen(List<int> addr, int port, int backlog, bool v6Only) |
| 530 native "ServerSocket_CreateBindListen"; | 533 native "ServerSocket_CreateBindListen"; |
| 531 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept"; | 534 nativeAccept(_NativeSocket socket) native "ServerSocket_Accept"; |
| 532 int nativeGetPort() native "Socket_GetPort"; | 535 int nativeGetPort() native "Socket_GetPort"; |
| 533 List nativeGetRemotePeer() native "Socket_GetRemotePeer"; | 536 List nativeGetRemotePeer() native "Socket_GetRemotePeer"; |
| 534 OSError nativeGetError() native "Socket_GetError"; | 537 OSError nativeGetError() native "Socket_GetError"; |
| 535 bool nativeSetOption(int option, bool enabled) native "Socket_SetOption"; | 538 bool nativeSetOption(int option, bool enabled) native "Socket_SetOption"; |
| 536 | 539 |
| 537 static SendPort newServicePort() native "Socket_NewServicePort"; | 540 static SendPort newServicePort() native "Socket_NewServicePort"; |
| 538 } | 541 } |
| 539 | 542 |
| 540 | 543 |
| 541 class _RawServerSocket extends Stream<RawSocket> | 544 class _RawServerSocket extends Stream<RawSocket> |
| 542 implements RawServerSocket { | 545 implements RawServerSocket { |
| 543 final _NativeSocket _socket; | 546 final _NativeSocket _socket; |
| 544 StreamController<RawSocket> _controller; | 547 StreamController<RawSocket> _controller; |
| 545 | 548 |
| 546 static Future<_RawServerSocket> bind(address, | 549 static Future<_RawServerSocket> bind(address, |
| 547 int port, | 550 int port, |
| 548 int backlog) { | 551 int backlog, |
| 552 bool v6Only) { |
| 549 if (port < 0 || port > 0xFFFF) | 553 if (port < 0 || port > 0xFFFF) |
| 550 throw new ArgumentError("Invalid port $port"); | 554 throw new ArgumentError("Invalid port $port"); |
| 551 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); | 555 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); |
| 552 return _NativeSocket.bind(address, port, backlog) | 556 return _NativeSocket.bind(address, port, backlog, v6Only) |
| 553 .then((socket) => new _RawServerSocket(socket)); | 557 .then((socket) => new _RawServerSocket(socket)); |
| 554 } | 558 } |
| 555 | 559 |
| 556 _RawServerSocket(this._socket) { | 560 _RawServerSocket(this._socket) { |
| 557 _controller = new StreamController( | 561 _controller = new StreamController( |
| 558 onListen: _onSubscriptionStateChange, | 562 onListen: _onSubscriptionStateChange, |
| 559 onCancel: _onSubscriptionStateChange, | 563 onCancel: _onSubscriptionStateChange, |
| 560 onPause: _onPauseStateChange, | 564 onPause: _onPauseStateChange, |
| 561 onResume: _onPauseStateChange); | 565 onResume: _onPauseStateChange); |
| 562 _socket.closeFuture.then((_) => _controller.close()); | 566 _socket.closeFuture.then((_) => _controller.close()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 _socket.setListening(read: true, write: false); | 599 _socket.setListening(read: true, write: false); |
| 596 } | 600 } |
| 597 | 601 |
| 598 void _onSubscriptionStateChange() { | 602 void _onSubscriptionStateChange() { |
| 599 if (_controller.hasListener) { | 603 if (_controller.hasListener) { |
| 600 _resume(); | 604 _resume(); |
| 601 } else { | 605 } else { |
| 602 close(); | 606 close(); |
| 603 } | 607 } |
| 604 } | 608 } |
| 609 |
| 605 void _onPauseStateChange() { | 610 void _onPauseStateChange() { |
| 606 if (_controller.isPaused) { | 611 if (_controller.isPaused) { |
| 607 _pause(); | 612 _pause(); |
| 608 } else { | 613 } else { |
| 609 _resume(); | 614 _resume(); |
| 610 } | 615 } |
| 611 } | 616 } |
| 612 } | 617 } |
| 613 | 618 |
| 614 | 619 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 } else { | 737 } else { |
| 733 close(); | 738 close(); |
| 734 } | 739 } |
| 735 } | 740 } |
| 736 } | 741 } |
| 737 | 742 |
| 738 | 743 |
| 739 patch class ServerSocket { | 744 patch class ServerSocket { |
| 740 /* patch */ static Future<ServerSocket> bind(address, | 745 /* patch */ static Future<ServerSocket> bind(address, |
| 741 int port, | 746 int port, |
| 742 {int backlog: 0}) { | 747 {int backlog: 0, |
| 743 return _ServerSocket.bind(address, port, backlog); | 748 bool v6Only: false}) { |
| 749 return _ServerSocket.bind(address, port, backlog, v6Only); |
| 744 } | 750 } |
| 745 } | 751 } |
| 746 | 752 |
| 747 class _ServerSocket extends Stream<Socket> | 753 class _ServerSocket extends Stream<Socket> |
| 748 implements ServerSocket { | 754 implements ServerSocket { |
| 749 final _socket; | 755 final _socket; |
| 750 | 756 |
| 751 static Future<_ServerSocket> bind(address, | 757 static Future<_ServerSocket> bind(address, |
| 752 int port, | 758 int port, |
| 753 int backlog) { | 759 int backlog, |
| 754 return _RawServerSocket.bind(address, port, backlog) | 760 bool v6Only) { |
| 761 return _RawServerSocket.bind(address, port, backlog, v6Only) |
| 755 .then((socket) => new _ServerSocket(socket)); | 762 .then((socket) => new _ServerSocket(socket)); |
| 756 } | 763 } |
| 757 | 764 |
| 758 _ServerSocket(this._socket); | 765 _ServerSocket(this._socket); |
| 759 | 766 |
| 760 StreamSubscription<Socket> listen(void onData(Socket event), | 767 StreamSubscription<Socket> listen(void onData(Socket event), |
| 761 {void onError(error), | 768 {void onError(error), |
| 762 void onDone(), | 769 void onDone(), |
| 763 bool cancelOnError}) { | 770 bool cancelOnError}) { |
| 764 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen( | 771 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen( |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 _raw.onBadCertificate = callback; | 1095 _raw.onBadCertificate = callback; |
| 1089 } | 1096 } |
| 1090 | 1097 |
| 1091 X509Certificate get peerCertificate { | 1098 X509Certificate get peerCertificate { |
| 1092 if (_raw == null) { | 1099 if (_raw == null) { |
| 1093 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 1100 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 1094 } | 1101 } |
| 1095 return _raw.peerCertificate; | 1102 return _raw.peerCertificate; |
| 1096 } | 1103 } |
| 1097 } | 1104 } |
| OLD | NEW |