Chromium Code Reviews| 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 = "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 InternetAddress get LOOPBACK_IP_V4 { | |
| 23 return _InternetAddress.LOOPBACK_IP_V4; | |
| 24 } | |
| 25 | |
| 26 /* patch */ static InternetAddress get LOOPBACK_IP_V6 { | |
| 27 return _InternetAddress.LOOPBACK_IP_V6; | |
| 28 } | |
| 29 | |
| 30 /* patch */ static InternetAddress get ANY_IP_V4 { | |
| 31 return _InternetAddress.ANY_IP_V4; | |
| 32 } | |
| 33 | |
| 34 /* patch */ static InternetAddress get ANY_IP_V6 { | |
| 35 return _InternetAddress.ANY_IP_V6; | |
| 36 } | |
| 37 | |
| 22 /* patch */ static Future<List<InternetAddress>> lookup( | 38 /* patch */ static Future<List<InternetAddress>> lookup( |
| 23 String host, {InternetAddressType type: InternetAddressType.IPv4}) { | 39 String host, {InternetAddressType type: InternetAddressType.IP_V4}) { |
| 24 return _NativeSocket.lookup(host, type: type); | 40 return _NativeSocket.lookup(host, type: type); |
| 25 } | 41 } |
| 26 } | 42 } |
| 27 | 43 |
| 28 class _InternetAddress implements InternetAddress { | 44 class _InternetAddress implements InternetAddress { |
| 45 static const int _ADDRESS_LOOPBACK_IP_V4 = 0; | |
| 46 static const int _ADDRESS_LOOPBACK_IP_V6 = 1; | |
| 47 static const int _ADDRESS_ANY_IP_V4 = 2; | |
| 48 static const int _ADDRESS_ANY_IP_V6 = 3; | |
| 49 | |
| 50 static _InternetAddress LOOPBACK_IP_V4 = | |
| 51 new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V4); | |
| 52 static _InternetAddress LOOPBACK_IP_V6 = | |
| 53 new _InternetAddress.fixed(_ADDRESS_LOOPBACK_IP_V6); | |
| 54 static _InternetAddress ANY_IP_V4 = | |
| 55 new _InternetAddress.fixed(_ADDRESS_ANY_IP_V4); | |
| 56 static _InternetAddress ANY_IP_V6 = | |
| 57 new _InternetAddress.fixed(_ADDRESS_ANY_IP_V6); | |
| 58 | |
| 29 final InternetAddressType type; | 59 final InternetAddressType type; |
| 30 final String address; | 60 final String address; |
| 31 final String host; | 61 final String host; |
| 32 final Uint8List _sockaddr_storage; | 62 final Uint8List _sockaddr_storage; |
| 33 | 63 |
| 34 _InternetAddress(InternetAddressType this.type, | 64 _InternetAddress(InternetAddressType this.type, |
| 35 String this.address, | 65 String this.address, |
| 36 String this.host, | 66 String this.host, |
| 37 List<int> this._sockaddr_storage); | 67 List<int> this._sockaddr_storage); |
| 38 | 68 |
| 69 factory _InternetAddress.fixed(int id) { | |
| 70 switch (id) { | |
|
Bill Hesse
2013/04/30 10:50:22
Maybe put var sockaddr = _fixed(id)
before the swi
Søren Gjesse
2013/04/30 11:28:41
Done.
| |
| 71 case _ADDRESS_LOOPBACK_IP_V4: | |
| 72 return new _InternetAddress( | |
| 73 InternetAddressType.IP_V4, "127.0.0.1", "localhost", _fixed(id)); | |
| 74 case _ADDRESS_LOOPBACK_IP_V6: | |
| 75 return new _InternetAddress( | |
| 76 InternetAddressType.IP_V6, "::1", "ip6-localhost", _fixed(id)); | |
| 77 case _ADDRESS_ANY_IP_V4: | |
| 78 return new _InternetAddress( | |
| 79 InternetAddressType.IP_V4, "0.0.0.0", "0.0.0.0", _fixed(id)); | |
| 80 case _ADDRESS_ANY_IP_V6: | |
| 81 return new _InternetAddress( | |
| 82 InternetAddressType.IP_V6, "::", "::", _fixed(id)); | |
| 83 default: | |
| 84 assert(false); | |
|
Bill Hesse
2013/04/30 10:50:22
There is no return value for the function in the d
Søren Gjesse
2013/04/30 11:28:41
Done.
| |
| 85 } | |
| 86 } | |
| 87 | |
| 39 String toString() { | 88 String toString() { |
| 40 return "InternetAddress('$address', ${type.name})"; | 89 return "InternetAddress('$address', ${type.name})"; |
| 41 } | 90 } |
| 91 | |
| 92 static Uint8List _fixed(int id) native "InternetAddress_Fixed"; | |
| 42 } | 93 } |
| 43 | 94 |
| 44 | 95 |
| 45 // The _NativeSocket class encapsulates an OS socket. | 96 // The _NativeSocket class encapsulates an OS socket. |
| 46 class _NativeSocket extends NativeFieldWrapperClass1 { | 97 class _NativeSocket extends NativeFieldWrapperClass1 { |
| 47 // Bit flags used when communicating between the eventhandler and | 98 // Bit flags used when communicating between the eventhandler and |
| 48 // dart code. The EVENT flags are used to indicate events of | 99 // dart code. The EVENT flags are used to indicate events of |
| 49 // interest when sending a message from dart code to the | 100 // interest when sending a message from dart code to the |
| 50 // eventhandler. When receiving a message from the eventhandler the | 101 // eventhandler. When receiving a message from the eventhandler the |
| 51 // EVENT flags indicate the events that actually happened. The | 102 // EVENT flags indicate the events that actually happened. The |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 // Holds the port of the socket, null if not known. | 149 // Holds the port of the socket, null if not known. |
| 99 int localPort; | 150 int localPort; |
| 100 | 151 |
| 101 // Holds the address used to connect or bind the socket. | 152 // Holds the address used to connect or bind the socket. |
| 102 InternetAddress address; | 153 InternetAddress address; |
| 103 | 154 |
| 104 // Native port for socket services. | 155 // Native port for socket services. |
| 105 static SendPort socketService; | 156 static SendPort socketService; |
| 106 | 157 |
| 107 static Future<List<InternetAddress>> lookup( | 158 static Future<List<InternetAddress>> lookup( |
| 108 String host, {InternetAddressType type: InternetAddressType.IPv4}) { | 159 String host, {InternetAddressType type: InternetAddressType.IP_V4}) { |
| 109 ensureSocketService(); | 160 ensureSocketService(); |
| 110 return socketService.call([HOST_NAME_LOOKUP, host, type._value]) | 161 return socketService.call([HOST_NAME_LOOKUP, host, type._value]) |
| 111 .then((response) { | 162 .then((response) { |
| 112 if (isErrorResponse(response)) { | 163 if (isErrorResponse(response)) { |
| 113 throw createError(response, "Failed host name lookup"); | 164 throw createError(response, "Failed host name lookup"); |
| 114 } else { | 165 } else { |
| 115 return response.skip(1).map((result) { | 166 return response.skip(1).map((result) { |
| 116 var type = new InternetAddressType._from(result[0]); | 167 var type = new InternetAddressType._from(result[0]); |
| 117 return new _InternetAddress(type, result[1], host, result[2]); | 168 return new _InternetAddress(type, result[1], host, result[2]); |
| 118 }).toList(); | 169 }).toList(); |
| (...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1035 _raw.onBadCertificate = callback; | 1086 _raw.onBadCertificate = callback; |
| 1036 } | 1087 } |
| 1037 | 1088 |
| 1038 X509Certificate get peerCertificate { | 1089 X509Certificate get peerCertificate { |
| 1039 if (_raw == null) { | 1090 if (_raw == null) { |
| 1040 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 1091 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 1041 } | 1092 } |
| 1042 return _raw.peerCertificate; | 1093 return _raw.peerCertificate; |
| 1043 } | 1094 } |
| 1044 } | 1095 } |
| OLD | NEW |