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 bool v6Only: false, | 9 bool v6Only: false, |
10 bool shared: false}) { | 10 bool shared: false}) { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 bool writeEventIssued = false; | 328 bool writeEventIssued = false; |
329 bool writeAvailable = false; | 329 bool writeAvailable = false; |
330 | 330 |
331 static bool connectedResourceHandler = false; | 331 static bool connectedResourceHandler = false; |
332 _ReadWriteResourceInfo resourceInfo; | 332 _ReadWriteResourceInfo resourceInfo; |
333 | 333 |
334 // The owner object is the object that the Socket is being used by, e.g. | 334 // The owner object is the object that the Socket is being used by, e.g. |
335 // a HttpServer, a WebSocket connection, a process pipe, etc. | 335 // a HttpServer, a WebSocket connection, a process pipe, etc. |
336 Object owner; | 336 Object owner; |
337 | 337 |
338 static double get timestamp => sw.elapsedMicroseconds / 1000000.0; | |
339 | |
340 static Future<List<InternetAddress>> lookup( | 338 static Future<List<InternetAddress>> lookup( |
341 String host, {InternetAddressType type: InternetAddressType.ANY}) { | 339 String host, {InternetAddressType type: InternetAddressType.ANY}) { |
342 return _IOService._dispatch(_SOCKET_LOOKUP, [host, type._value]) | 340 return _IOService._dispatch(_SOCKET_LOOKUP, [host, type._value]) |
343 .then((response) { | 341 .then((response) { |
344 if (isErrorResponse(response)) { | 342 if (isErrorResponse(response)) { |
345 throw createError(response, "Failed host lookup: '$host'"); | 343 throw createError(response, "Failed host lookup: '$host'"); |
346 } else { | 344 } else { |
347 return response.skip(1).map((result) { | 345 return response.skip(1).map((result) { |
348 var type = new InternetAddressType._from(result[0]); | 346 var type = new InternetAddressType._from(result[0]); |
349 return new _InternetAddress(result[1], host, result[2]); | 347 return new _InternetAddress(result[1], host, result[2]); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 if (sourceAddress is String) { | 394 if (sourceAddress is String) { |
397 sourceAddress = new InternetAddress(sourceAddress); | 395 sourceAddress = new InternetAddress(sourceAddress); |
398 } | 396 } |
399 } | 397 } |
400 return new Future.value(host) | 398 return new Future.value(host) |
401 .then((host) { | 399 .then((host) { |
402 if (host is _InternetAddress) return [host]; | 400 if (host is _InternetAddress) return [host]; |
403 return lookup(host) | 401 return lookup(host) |
404 .then((addresses) { | 402 .then((addresses) { |
405 if (addresses.isEmpty) { | 403 if (addresses.isEmpty) { |
406 throw createError(response, "Failed host lookup: '$host'"); | 404 throw createError(null, "Failed host lookup: '$host'"); |
407 } | 405 } |
408 return addresses; | 406 return addresses; |
409 }); | 407 }); |
410 }) | 408 }) |
411 .then((addresses) { | 409 .then((addresses) { |
412 assert(addresses is List); | 410 assert(addresses is List); |
413 var completer = new Completer(); | 411 var completer = new Completer(); |
414 var it = addresses.iterator; | 412 var it = addresses.iterator; |
415 var error = null; | 413 var error = null; |
416 var connecting = new HashMap(); | 414 var connecting = new HashMap(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 int backlog, | 496 int backlog, |
499 bool v6Only, | 497 bool v6Only, |
500 bool shared) { | 498 bool shared) { |
501 _throwOnBadPort(port); | 499 _throwOnBadPort(port); |
502 return new Future.value(host) | 500 return new Future.value(host) |
503 .then((host) { | 501 .then((host) { |
504 if (host is _InternetAddress) return host; | 502 if (host is _InternetAddress) return host; |
505 return lookup(host) | 503 return lookup(host) |
506 .then((list) { | 504 .then((list) { |
507 if (list.length == 0) { | 505 if (list.length == 0) { |
508 throw createError(response, "Failed host lookup: '$host'"); | 506 throw createError(null, "Failed host lookup: '$host'"); |
509 } | 507 } |
510 return list[0]; | 508 return list[0]; |
511 }); | 509 }); |
512 }) | 510 }) |
513 .then((address) { | 511 .then((address) { |
514 var socket = new _NativeSocket.listen(); | 512 var socket = new _NativeSocket.listen(); |
515 socket.localAddress = address; | 513 socket.localAddress = address; |
516 var result = socket.nativeCreateBindListen(address._in_addr, | 514 var result = socket.nativeCreateBindListen(address._in_addr, |
517 port, | 515 port, |
518 backlog, | 516 backlog, |
(...skipping 18 matching lines...) Expand all Loading... |
537 | 535 |
538 static Future<_NativeSocket> bindDatagram( | 536 static Future<_NativeSocket> bindDatagram( |
539 host, int port, bool reuseAddress) { | 537 host, int port, bool reuseAddress) { |
540 _throwOnBadPort(port); | 538 _throwOnBadPort(port); |
541 return new Future.value(host) | 539 return new Future.value(host) |
542 .then((host) { | 540 .then((host) { |
543 if (host is _InternetAddress) return host; | 541 if (host is _InternetAddress) return host; |
544 return lookup(host) | 542 return lookup(host) |
545 .then((list) { | 543 .then((list) { |
546 if (list.length == 0) { | 544 if (list.length == 0) { |
547 throw createError(response, "Failed host lookup: '$host'"); | 545 throw createError(null, "Failed host lookup: '$host'"); |
548 } | 546 } |
549 return list[0]; | 547 return list[0]; |
550 }); | 548 }); |
551 }) | 549 }) |
552 .then((address) { | 550 .then((address) { |
553 var socket = new _NativeSocket.datagram(address); | 551 var socket = new _NativeSocket.datagram(address); |
554 var result = socket.nativeCreateBindDatagram( | 552 var result = socket.nativeCreateBindDatagram( |
555 address._in_addr, port, reuseAddress); | 553 address._in_addr, port, reuseAddress); |
556 if (result is OSError) { | 554 if (result is OSError) { |
557 throw new SocketException("Failed to create datagram socket", | 555 throw new SocketException("Failed to create datagram socket", |
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1877 Datagram _makeDatagram(List<int> data, | 1875 Datagram _makeDatagram(List<int> data, |
1878 String address, | 1876 String address, |
1879 List<int> in_addr, | 1877 List<int> in_addr, |
1880 int port) { | 1878 int port) { |
1881 return new Datagram( | 1879 return new Datagram( |
1882 data, | 1880 data, |
1883 new _InternetAddress(address, null, in_addr), | 1881 new _InternetAddress(address, null, in_addr), |
1884 port); | 1882 port); |
1885 } | 1883 } |
1886 | 1884 |
OLD | NEW |