Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: sdk/lib/io/socket.dart

Issue 14083007: Add new InternetAddress class with a static lookup function (including IPv6 results). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleanup from review. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« runtime/bin/socket_linux.cc ('K') | « runtime/bin/vmstats_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 part of dart.io; 5 part of dart.io;
6 6
7
8 class InternetAddressType {
9 static const InternetAddressType IPv4 = const InternetAddressType._(0);
10 static const InternetAddressType IPv6 = const InternetAddressType._(1);
11
12 final int _value;
13
14 const InternetAddressType._(String this._value);
15
16 String get name {
17 switch (_value) {
18 case 0: return "IPv4";
19 case 1: return "IPv6";
20 default: throw new ArgumentError("Invalid InternetAddress");
21 }
22 }
23
24 String toString() => "InternetAddressType($name)";
25
26 int get hashCode => _value;
27
28 bool operator==(other) => _value == other._value;
29 }
30
31 abstract class InternetAddress {
32 InternetAddressType type;
33 String get address;
34
35 external static Future<List<InternetAddress>> lookup(String host);
36 }
37
7 /** 38 /**
8 * The RawServerSocket is a server socket, providing a stream of low-level 39 * The RawServerSocket is a server socket, providing a stream of low-level
9 * [RawSocket]s. 40 * [RawSocket]s.
10 * 41 *
11 * See [RawSocket] for more info. 42 * See [RawSocket] for more info.
12 */ 43 */
13 abstract class RawServerSocket implements Stream<RawSocket> { 44 abstract class RawServerSocket implements Stream<RawSocket> {
14 /** 45 /**
15 * Returns a future for a [:RawServerSocket:]. When the future 46 * Returns a future for a [:RawServerSocket:]. When the future
16 * completes the server socket is bound to the given [address] and 47 * completes the server socket is bound to the given [address] and
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 168
138 /** 169 /**
139 * The [RawSocket] is a low-level interface to a socket, exposing the raw 170 * The [RawSocket] is a low-level interface to a socket, exposing the raw
140 * events signaled by the system. It's a [Stream] of [RawSocketEvent]s. 171 * events signaled by the system. It's a [Stream] of [RawSocketEvent]s.
141 */ 172 */
142 abstract class RawSocket implements Stream<RawSocketEvent> { 173 abstract class RawSocket implements Stream<RawSocketEvent> {
143 /** 174 /**
144 * Creates a new socket connection to the host and port and returns a [Future] 175 * Creates a new socket connection to the host and port and returns a [Future]
145 * that will complete with either a [RawSocket] once connected or an error 176 * that will complete with either a [RawSocket] once connected or an error
146 * if the host-lookup or connection failed. 177 * if the host-lookup or connection failed.
178 *
179 * [host] can either be a [String] or an [InternetAddress]. If [host] is a
180 * [String], [connect] will perform a [InternetAddress.lookup] and use
181 * the first value in the list.
147 */ 182 */
148 external static Future<RawSocket> connect(String host, int port); 183 external static Future<RawSocket> connect(host, int port);
149 184
150 /** 185 /**
151 * Returns the number of received and non-read bytes in the socket that 186 * Returns the number of received and non-read bytes in the socket that
152 * can be read. 187 * can be read.
153 */ 188 */
154 int available(); 189 int available();
155 190
156 /** 191 /**
157 * Read up to [len] bytes from the socket. This function is 192 * Read up to [len] bytes from the socket. This function is
158 * non-blocking and will only return data if data is available. The 193 * non-blocking and will only return data if data is available. The
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 /** 266 /**
232 * A high-level class for communicating over a TCP socket. The [Socket] exposes 267 * A high-level class for communicating over a TCP socket. The [Socket] exposes
233 * both a [Stream] and a [IOSink] interface, making it ideal for 268 * both a [Stream] and a [IOSink] interface, making it ideal for
234 * using together with other [Stream]s. 269 * using together with other [Stream]s.
235 */ 270 */
236 abstract class Socket implements Stream<List<int>>, IOSink { 271 abstract class Socket implements Stream<List<int>>, IOSink {
237 /** 272 /**
238 * Creats a new socket connection to the host and port and returns a [Future] 273 * Creats a new socket connection to the host and port and returns a [Future]
239 * that will complete with either a [Socket] once connected or an error 274 * that will complete with either a [Socket] once connected or an error
240 * if the host-lookup or connection failed. 275 * if the host-lookup or connection failed.
276 *
277 * [host] can either be a [String] or an [InternetAddress]. If [host] is a
278 * [String], [connect] will perform a [InternetAddress.lookup] and use
279 * the first value in the list.
241 */ 280 */
242 external static Future<Socket> connect(String host, int port); 281 external static Future<Socket> connect(host, int port);
243 282
244 /** 283 /**
245 * Destroy the socket in both directions. Calling [destroy] will make the 284 * Destroy the socket in both directions. Calling [destroy] will make the
246 * send a close event on the stream and will no longer react on data being 285 * send a close event on the stream and will no longer react on data being
247 * piped to it. 286 * piped to it.
248 * 287 *
249 * Call [close](inherited from [IOSink]) to only close the [Socket] 288 * Call [close](inherited from [IOSink]) to only close the [Socket]
250 * for sending data. 289 * for sending data.
251 */ 290 */
252 void destroy(); 291 void destroy();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 sb.write(" ($osError)"); 332 sb.write(" ($osError)");
294 } 333 }
295 } else if (osError != null) { 334 } else if (osError != null) {
296 sb.write(": $osError"); 335 sb.write(": $osError");
297 } 336 }
298 return sb.toString(); 337 return sb.toString();
299 } 338 }
300 final String message; 339 final String message;
301 final OSError osError; 340 final OSError osError;
302 } 341 }
OLDNEW
« runtime/bin/socket_linux.cc ('K') | « runtime/bin/vmstats_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698