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

Side by Side Diff: runtime/bin/socket_patch.dart

Issue 259353003: Make Socket::connect try all addresses given. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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
« no previous file with comments | « no previous file | sdk/lib/io/socket.dart » ('j') | sdk/lib/io/socket.dart » ('J')
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 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 return _RawServerSocket.bind(address, port, backlog, v6Only); 10 return _RawServerSocket.bind(address, port, backlog, v6Only);
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 return map; 474 return map;
475 }); 475 });
476 return map.values.toList(); 476 return map.values.toList();
477 } 477 }
478 }); 478 });
479 } 479 }
480 480
481 static Future<_NativeSocket> connect(host, int port) { 481 static Future<_NativeSocket> connect(host, int port) {
482 return new Future.value(host) 482 return new Future.value(host)
483 .then((host) { 483 .then((host) {
484 if (host is _InternetAddress) return host; 484 if (host is _InternetAddress) return [host];
485 if (host is List) {
Søren Gjesse 2014/04/30 13:11:56 We don't want to support a List here.
Anders Johnsen 2014/05/01 06:31:23 Done.
486 for (var entry in host) {
487 if (entry is! _InternetAddress) {
488 throw new ArgumentError(
489 "When passing a List as `host`, the entries"
490 " must be InternetAddresses");
491 }
492 }
493 return host;
494 }
485 return lookup(host) 495 return lookup(host)
486 .then((list) { 496 .then((list) {
487 if (list.length == 0) { 497 if (list.length == 0) {
488 throw createError(response, "Failed host lookup: '$host'"); 498 throw createError(response, "Failed host lookup: '$host'");
489 } 499 }
490 return list[0]; 500 return list;
491 }); 501 });
492 }) 502 })
493 .then((address) { 503 .then((addresses) {
494 var socket = new _NativeSocket.normal(); 504 assert(addresses is List);
495 socket.address = address; 505 var completer = new Completer();
496 var result = socket.nativeCreateConnect( 506 var it = addresses.iterator;
497 address._in_addr, port); 507 void run(error) {
498 if (result is OSError) { 508 if (!it.moveNext()) {
499 throw createError(result, "Connection failed", address, port); 509 assert(error != null);
500 } else { 510 completer.completeError(error);
Søren Gjesse 2014/04/30 13:11:56 This will just return the error from the last one
Ivan Posva 2014/04/30 16:28:06 You could collect them all in a List and have a mu
Anders Johnsen 2014/05/01 06:31:23 It's just hard to fit in our current model, withou
501 socket.port; // Query the local port, for error messages. 511 return;
502 var completer = new Completer(); 512 }
503 // Setup handlers for receiving the first write event which 513 var address = it.current;
504 // indicate that the socket is fully connected. 514 var socket = new _NativeSocket.normal();
505 socket.setHandlers( 515 socket.address = address;
506 write: () { 516 var result = socket.nativeCreateConnect(address._in_addr, port);
507 socket.setListening(read: false, write: false); 517 if (result is OSError) {
508 completer.complete(socket); 518 run(createError(result, "Connection failed", address, port));
509 }, 519 } else {
510 error: (e) { 520 socket.port; // Query the local port, for error messages.
511 socket.close(); 521 // Setup handlers for receiving the first write event which
512 completer.completeError(e); 522 // indicate that the socket is fully connected.
513 } 523 socket.setHandlers(
514 ); 524 write: () {
515 socket.setListening(read: false, write: true); 525 socket.setListening(read: false, write: false);
516 return completer.future; 526 completer.complete(socket);
527 },
528 error: (e) {
529 socket.close();
530 run(e);
531 }
532 );
533 socket.setListening(read: false, write: true);
534 }
517 } 535 }
536 run(null);
537 return completer.future;
518 }); 538 });
519 } 539 }
520 540
521 static Future<_NativeSocket> bind(host, 541 static Future<_NativeSocket> bind(host,
522 int port, 542 int port,
523 int backlog, 543 int backlog,
524 bool v6Only) { 544 bool v6Only) {
525 return new Future.value(host) 545 return new Future.value(host)
526 .then((host) { 546 .then((host) {
527 if (host is _InternetAddress) return host; 547 if (host is _InternetAddress) return host;
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 String address, 1800 String address,
1781 List<int> in_addr, 1801 List<int> in_addr,
1782 int port) { 1802 int port) {
1783 return new Datagram( 1803 return new Datagram(
1784 data, 1804 data,
1785 new _InternetAddress(address, null, in_addr), 1805 new _InternetAddress(address, null, in_addr),
1786 port); 1806 port);
1787 } 1807 }
1788 1808
1789 String _socketsStats() => _SocketsObservatory.toJSON(); 1809 String _socketsStats() => _SocketsObservatory.toJSON();
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/socket.dart » ('j') | sdk/lib/io/socket.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698