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 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 Loading... |
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 /** | 261 /** |
227 * A high-level class for communicating over a TCP socket. The [Socket] exposes | 262 * A high-level class for communicating over a TCP socket. The [Socket] exposes |
228 * both a [Stream] and a [IOSink] interface, making it ideal for | 263 * both a [Stream] and a [IOSink] interface, making it ideal for |
229 * using together with other [Stream]s. | 264 * using together with other [Stream]s. |
230 */ | 265 */ |
231 abstract class Socket implements Stream<List<int>>, IOSink { | 266 abstract class Socket implements Stream<List<int>>, IOSink { |
232 /** | 267 /** |
233 * Creats a new socket connection to the host and port and returns a [Future] | 268 * Creats a new socket connection to the host and port and returns a [Future] |
234 * that will complete with either a [Socket] once connected or an error | 269 * that will complete with either a [Socket] once connected or an error |
235 * if the host-lookup or connection failed. | 270 * if the host-lookup or connection failed. |
| 271 * |
| 272 * [host] can either be a [String] or an [InternetAddress]. If [host] is a |
| 273 * [String], [connect] will perform a [InternetAddress.lookup] and use |
| 274 * the first value in the list. |
236 */ | 275 */ |
237 external static Future<Socket> connect(String host, int port); | 276 external static Future<Socket> connect(host, int port); |
238 | 277 |
239 /** | 278 /** |
240 * Destroy the socket in both directions. Calling [destroy] will make the | 279 * Destroy the socket in both directions. Calling [destroy] will make the |
241 * send a close event on the stream and will no longer react on data being | 280 * send a close event on the stream and will no longer react on data being |
242 * piped to it. | 281 * piped to it. |
243 * | 282 * |
244 * Call [close](inherited from [IOSink]) to only close the [Socket] | 283 * Call [close](inherited from [IOSink]) to only close the [Socket] |
245 * for sending data. | 284 * for sending data. |
246 */ | 285 */ |
247 void destroy(); | 286 void destroy(); |
(...skipping 24 matching lines...) Expand all Loading... |
272 sb.write(" ($osError)"); | 311 sb.write(" ($osError)"); |
273 } | 312 } |
274 } else if (osError != null) { | 313 } else if (osError != null) { |
275 sb.write(": $osError"); | 314 sb.write(": $osError"); |
276 } | 315 } |
277 return sb.toString(); | 316 return sb.toString(); |
278 } | 317 } |
279 final String message; | 318 final String message; |
280 final OSError osError; | 319 final OSError osError; |
281 } | 320 } |
OLD | NEW |