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 import 'dart:io'; | 5 import 'dart:io'; |
6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
7 | 7 |
8 const ANY = InternetAddressType.ANY; | 8 const ANY = InternetAddressType.ANY; |
9 | 9 |
10 void testIPv6toIPv6() { | 10 void testIPv6toIPv6() { |
11 InternetAddress.lookup("::0", type: ANY).then((serverAddr) { | 11 InternetAddress.lookup("::0", type: ANY).then((serverAddr) { |
12 InternetAddress.lookup("::1", type: ANY).then((clientAddr) { | 12 InternetAddress.lookup("::1", type: ANY).then((clientAddr) { |
13 ServerSocket.bind(serverAddr.first).then((server) { | 13 ServerSocket.bind(serverAddr.first, 0).then((server) { |
14 server.listen((socket) { | 14 server.listen((socket) { |
15 socket.destroy(); | 15 socket.destroy(); |
16 server.close(); | 16 server.close(); |
17 }); | 17 }); |
18 Socket.connect(clientAddr.first, server.port).then((socket) { | 18 Socket.connect(clientAddr.first, server.port).then((socket) { |
19 socket.destroy(); | 19 socket.destroy(); |
20 }); | 20 }); |
21 }); | 21 }); |
22 }); | 22 }); |
23 }); | 23 }); |
24 } | 24 } |
25 | 25 |
26 void testIPv4toIPv6() { | 26 void testIPv4toIPv6() { |
27 InternetAddress.lookup("::0", type: ANY).then((serverAddr) { | 27 InternetAddress.lookup("::0", type: ANY).then((serverAddr) { |
28 ServerSocket.bind(serverAddr.first).then((server) { | 28 ServerSocket.bind(serverAddr.first, 0).then((server) { |
29 server.listen((socket) { | 29 server.listen((socket) { |
30 socket.destroy(); | 30 socket.destroy(); |
31 server.close(); | 31 server.close(); |
32 }); | 32 }); |
33 Socket.connect("127.0.0.1", server.port).then((socket) { | 33 Socket.connect("127.0.0.1", server.port).then((socket) { |
34 socket.destroy(); | 34 socket.destroy(); |
35 }); | 35 }); |
36 }); | 36 }); |
37 }); | 37 }); |
38 } | 38 } |
39 | 39 |
40 void testIPv6toIPv4() { | 40 void testIPv6toIPv4() { |
41 InternetAddress.lookup("::1", type: ANY).then((clientAddr) { | 41 InternetAddress.lookup("::1", type: ANY).then((clientAddr) { |
42 ServerSocket.bind("127.0.0.1").then((server) { | 42 ServerSocket.bind("127.0.0.1", 0).then((server) { |
43 server.listen((socket) { | 43 server.listen((socket) { |
44 throw "Unexpected socket"; | 44 throw "Unexpected socket"; |
45 }); | 45 }); |
46 Socket.connect(clientAddr.first, server.port).catchError((e) { | 46 Socket.connect(clientAddr.first, server.port).catchError((e) { |
47 server.close(); | 47 server.close(); |
48 }); | 48 }); |
49 }); | 49 }); |
50 }); | 50 }); |
51 } | 51 } |
52 | 52 |
53 void testIPv4toIPv4() { | 53 void testIPv4toIPv4() { |
54 ServerSocket.bind("127.0.0.1").then((server) { | 54 ServerSocket.bind("127.0.0.1", 0).then((server) { |
55 server.listen((socket) { | 55 server.listen((socket) { |
56 socket.destroy(); | 56 socket.destroy(); |
57 server.close(); | 57 server.close(); |
58 }); | 58 }); |
59 Socket.connect("127.0.0.1", server.port).then((socket) { | 59 Socket.connect("127.0.0.1", server.port).then((socket) { |
60 socket.destroy(); | 60 socket.destroy(); |
61 }); | 61 }); |
62 }); | 62 }); |
63 } | 63 } |
64 | 64 |
(...skipping 24 matching lines...) Expand all Loading... |
89 } | 89 } |
90 | 90 |
91 void main() { | 91 void main() { |
92 testIPv6toIPv6(); | 92 testIPv6toIPv6(); |
93 testIPv4toIPv6(); | 93 testIPv4toIPv6(); |
94 testIPv6toIPv4(); | 94 testIPv6toIPv4(); |
95 testIPv4toIPv4(); | 95 testIPv4toIPv4(); |
96 testIPv6Lookup(); | 96 testIPv6Lookup(); |
97 testIPv4Lookup(); | 97 testIPv4Lookup(); |
98 } | 98 } |
OLD | NEW |