| 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([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 } |
| 11 } | 11 } |
| 12 | 12 |
| 13 | 13 |
| 14 patch class RawSocket { | 14 patch class RawSocket { |
| 15 /* patch */ static Future<RawSocket> connect(host, int port) { | 15 /* patch */ static Future<RawSocket> connect(host, int port) { |
| 16 return _RawSocket.connect(host, port); | 16 return _RawSocket.connect(host, port); |
| 17 } | 17 } |
| 18 } | 18 } |
| 19 | 19 |
| 20 | 20 |
| 21 patch class InternetAddress { | 21 patch class InternetAddress { |
| 22 /* patch */ static Future<List<InternetAddress>> lookup( | 22 /* patch */ static Future<List<InternetAddress>> lookup( |
| 23 String host, {InternetAddressType type: InternetAddressType.ANY}) { | 23 String host, {InternetAddressType type: InternetAddressType.IPv4}) { |
| 24 return _NativeSocket.lookup(host, type: type); | 24 return _NativeSocket.lookup(host, type: type); |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 class _InternetAddress implements InternetAddress { | 28 class _InternetAddress implements InternetAddress { |
| 29 final InternetAddressType type; | 29 final InternetAddressType type; |
| 30 final String address; | 30 final String address; |
| 31 final String host; | 31 final String host; |
| 32 final Uint8List _sockaddr_storage; | 32 final Uint8List _sockaddr_storage; |
| 33 | 33 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Holds the port of the socket, null if not known. | 98 // Holds the port of the socket, null if not known. |
| 99 int localPort; | 99 int localPort; |
| 100 | 100 |
| 101 // Holds the address used to connect or bind the socket. | 101 // Holds the address used to connect or bind the socket. |
| 102 InternetAddress address; | 102 InternetAddress address; |
| 103 | 103 |
| 104 // Native port for socket services. | 104 // Native port for socket services. |
| 105 static SendPort socketService; | 105 static SendPort socketService; |
| 106 | 106 |
| 107 static Future<List<InternetAddress>> lookup( | 107 static Future<List<InternetAddress>> lookup( |
| 108 String host, {InternetAddressType type: InternetAddressType.ANY}) { | 108 String host, {InternetAddressType type: InternetAddressType.IPv4}) { |
| 109 ensureSocketService(); | 109 ensureSocketService(); |
| 110 return socketService.call([HOST_NAME_LOOKUP, host, type._value]) | 110 return socketService.call([HOST_NAME_LOOKUP, host, type._value]) |
| 111 .then((response) { | 111 .then((response) { |
| 112 if (isErrorResponse(response)) { | 112 if (isErrorResponse(response)) { |
| 113 throw createError(response, "Failed host name lookup"); | 113 throw createError(response, "Failed host name lookup"); |
| 114 } else { | 114 } else { |
| 115 return response.skip(1).map((result) { | 115 return response.skip(1).map((result) { |
| 116 var type = new InternetAddressType._from(result[0]); | 116 var type = new InternetAddressType._from(result[0]); |
| 117 return new _InternetAddress(type, result[1], host, result[2]); | 117 return new _InternetAddress(type, result[1], host, result[2]); |
| 118 }).toList(); | 118 }).toList(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 socket.close(); | 153 socket.close(); |
| 154 completer.completeError(createError(e, "Connection failed")); | 154 completer.completeError(createError(e, "Connection failed")); |
| 155 } | 155 } |
| 156 ); | 156 ); |
| 157 socket.setListening(read: false, write: true); | 157 socket.setListening(read: false, write: true); |
| 158 return completer.future; | 158 return completer.future; |
| 159 } | 159 } |
| 160 }); | 160 }); |
| 161 } | 161 } |
| 162 | 162 |
| 163 static Future<_NativeSocket> bind(String address, | 163 static Future<_NativeSocket> bind(host, |
| 164 int port, | 164 int port, |
| 165 int backlog) { | 165 int backlog) { |
| 166 return lookup(address) | 166 return new Future.value(host) |
| 167 .then((list) { | 167 .then((host) { |
| 168 if (list.length == 0) { | 168 if (host is _InternetAddress) return host; |
| 169 throw createError(response, "Failed host name lookup"); | 169 return lookup(host) |
| 170 } | 170 .then((list) { |
| 171 return list[0]; | 171 if (list.length == 0) { |
| 172 throw createError(response, "Failed host name lookup"); |
| 173 } |
| 174 return list[0]; |
| 175 }); |
| 172 }) | 176 }) |
| 173 .then((address) { | 177 .then((address) { |
| 174 var socket = new _NativeSocket.listen(); | 178 var socket = new _NativeSocket.listen(); |
| 175 socket.address = address; | 179 socket.address = address; |
| 176 var result = socket.nativeCreateBindListen(address._sockaddr_storage, | 180 var result = socket.nativeCreateBindListen(address._sockaddr_storage, |
| 177 port, | 181 port, |
| 178 backlog); | 182 backlog); |
| 179 if (result is OSError) { | 183 if (result is OSError) { |
| 180 throw new SocketIOException( | 184 throw new SocketIOException( |
| 181 "Failed to create server socket", result); | 185 "Failed to create server socket", result); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 483 |
| 480 static SendPort newServicePort() native "Socket_NewServicePort"; | 484 static SendPort newServicePort() native "Socket_NewServicePort"; |
| 481 } | 485 } |
| 482 | 486 |
| 483 | 487 |
| 484 class _RawServerSocket extends Stream<RawSocket> | 488 class _RawServerSocket extends Stream<RawSocket> |
| 485 implements RawServerSocket { | 489 implements RawServerSocket { |
| 486 final _NativeSocket _socket; | 490 final _NativeSocket _socket; |
| 487 StreamController<RawSocket> _controller; | 491 StreamController<RawSocket> _controller; |
| 488 | 492 |
| 489 static Future<_RawServerSocket> bind(String address, | 493 static Future<_RawServerSocket> bind(address, |
| 490 int port, | 494 int port, |
| 491 int backlog) { | 495 int backlog) { |
| 492 if (port < 0 || port > 0xFFFF) | 496 if (port < 0 || port > 0xFFFF) |
| 493 throw new ArgumentError("Invalid port $port"); | 497 throw new ArgumentError("Invalid port $port"); |
| 494 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); | 498 if (backlog < 0) throw new ArgumentError("Invalid backlog $backlog"); |
| 495 return _NativeSocket.bind(address, port, backlog) | 499 return _NativeSocket.bind(address, port, backlog) |
| 496 .then((socket) => new _RawServerSocket(socket)); | 500 .then((socket) => new _RawServerSocket(socket)); |
| 497 } | 501 } |
| 498 | 502 |
| 499 _RawServerSocket(this._socket) { | 503 _RawServerSocket(this._socket) { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 if (_controller.hasListener) { | 677 if (_controller.hasListener) { |
| 674 _resume(); | 678 _resume(); |
| 675 } else { | 679 } else { |
| 676 close(); | 680 close(); |
| 677 } | 681 } |
| 678 } | 682 } |
| 679 } | 683 } |
| 680 | 684 |
| 681 | 685 |
| 682 patch class ServerSocket { | 686 patch class ServerSocket { |
| 683 /* patch */ static Future<ServerSocket> bind([String address = "127.0.0.1", | 687 /* patch */ static Future<ServerSocket> bind([address = "127.0.0.1", |
| 684 int port = 0, | 688 int port = 0, |
| 685 int backlog = 0]) { | 689 int backlog = 0]) { |
| 686 return _ServerSocket.bind(address, port, backlog); | 690 return _ServerSocket.bind(address, port, backlog); |
| 687 } | 691 } |
| 688 } | 692 } |
| 689 | 693 |
| 690 class _ServerSocket extends Stream<Socket> | 694 class _ServerSocket extends Stream<Socket> |
| 691 implements ServerSocket { | 695 implements ServerSocket { |
| 692 final _socket; | 696 final _socket; |
| 693 | 697 |
| 694 static Future<_ServerSocket> bind(String address, | 698 static Future<_ServerSocket> bind(address, |
| 695 int port, | 699 int port, |
| 696 int backlog) { | 700 int backlog) { |
| 697 return _RawServerSocket.bind(address, port, backlog) | 701 return _RawServerSocket.bind(address, port, backlog) |
| 698 .then((socket) => new _ServerSocket(socket)); | 702 .then((socket) => new _ServerSocket(socket)); |
| 699 } | 703 } |
| 700 | 704 |
| 701 _ServerSocket(this._socket); | 705 _ServerSocket(this._socket); |
| 702 | 706 |
| 703 StreamSubscription<Socket> listen(void onData(Socket event), | 707 StreamSubscription<Socket> listen(void onData(Socket event), |
| 704 {void onError(error), | 708 {void onError(error), |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 _raw.onBadCertificate = callback; | 1035 _raw.onBadCertificate = callback; |
| 1032 } | 1036 } |
| 1033 | 1037 |
| 1034 X509Certificate get peerCertificate { | 1038 X509Certificate get peerCertificate { |
| 1035 if (_raw == null) { | 1039 if (_raw == null) { |
| 1036 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 1040 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 1037 } | 1041 } |
| 1038 return _raw.peerCertificate; | 1042 return _raw.peerCertificate; |
| 1039 } | 1043 } |
| 1040 } | 1044 } |
| OLD | NEW |