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:async'; | 5 import 'dart:async'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:async_helper/async_helper.dart'; | 9 import 'package:async_helper/async_helper.dart'; |
10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 Expect.isTrue('$error'.contains('v6Only flag')); | 56 Expect.isTrue('$error'.contains('v6Only flag')); |
57 socket.close().whenComplete(asyncEnd); | 57 socket.close().whenComplete(asyncEnd); |
58 asyncEnd(); | 58 asyncEnd(); |
59 }); | 59 }); |
60 }); | 60 }); |
61 } | 61 } |
62 | 62 |
63 Future testBindDifferentAddresses(InternetAddress addr1, | 63 Future testBindDifferentAddresses(InternetAddress addr1, |
64 InternetAddress addr2, | 64 InternetAddress addr2, |
65 bool addr1V6Only, | 65 bool addr1V6Only, |
66 bool addr2V6Only) { | 66 bool addr2V6Only) async { |
67 int freePort = await freeIPv4AndIPv6Port(); | |
68 | |
67 asyncStart(); | 69 asyncStart(); |
68 return ServerSocket.bind( | 70 return ServerSocket.bind( |
69 addr1, 0, v6Only: addr1V6Only, shared: false).then((socket) { | 71 addr1, freePort, v6Only: addr1V6Only, shared: false).then((socket) { |
70 Expect.isTrue(socket.port > 0); | 72 Expect.isTrue(socket.port > 0); |
71 | 73 |
72 asyncStart(); | 74 asyncStart(); |
73 return ServerSocket.bind( | 75 return ServerSocket.bind( |
74 addr2, socket.port, v6Only: addr2V6Only, shared: false).then((socket2) { | 76 addr2, freePort, v6Only: addr2V6Only, shared: false).then((socket2) { |
75 Expect.equals(socket.port, socket2.port); | 77 Expect.equals(socket.port, socket2.port); |
76 | 78 |
77 return Future.wait([ | 79 return Future.wait([ |
78 socket.close().whenComplete(asyncEnd), | 80 socket.close().whenComplete(asyncEnd), |
79 socket2.close().whenComplete(asyncEnd), | 81 socket2.close().whenComplete(asyncEnd), |
80 ]); | 82 ]); |
81 }); | 83 }); |
82 }); | 84 }); |
83 } | 85 } |
84 | 86 |
(...skipping 18 matching lines...) Expand all Loading... | |
103 asyncEnd(); | 105 asyncEnd(); |
104 }); | 106 }); |
105 | 107 |
106 Socket client = await Socket.connect(host, socket2.port); | 108 Socket client = await Socket.connect(host, socket2.port); |
107 await client.close(); | 109 await client.close(); |
108 await client.drain(); | 110 await client.drain(); |
109 | 111 |
110 asyncEnd(); | 112 asyncEnd(); |
111 } | 113 } |
112 | 114 |
113 void main() { | 115 Future<int> freeIPv4AndIPv6Port() async { |
116 var socket = await ServerSocket.bind(InternetAddress.ANY_IP_V6, 0, v6Only: fal se); | |
kustermann
2016/05/26 16:56:27
long line
| |
117 int port = socket.port; | |
118 await socket.close(); | |
119 return port; | |
120 } | |
121 | |
122 void main() async { | |
123 asyncStart(); | |
124 await testBindDifferentAddresses(InternetAddress.ANY_IP_V6, | |
125 InternetAddress.ANY_IP_V4, | |
126 true, | |
127 false); | |
128 await testBindDifferentAddresses(InternetAddress.ANY_IP_V4, | |
129 InternetAddress.ANY_IP_V6, | |
130 false, | |
131 true); | |
132 | |
114 for (var host in ['127.0.0.1', '::1']) { | 133 for (var host in ['127.0.0.1', '::1']) { |
115 testBindShared(host, false); | 134 testBindShared(host, false); |
116 testBindShared(host, true); | 135 testBindShared(host, true); |
117 | 136 |
118 negTestBindSharedMismatch(host, false); | 137 negTestBindSharedMismatch(host, false); |
119 negTestBindSharedMismatch(host, true); | 138 negTestBindSharedMismatch(host, true); |
120 | 139 |
121 negTestBindV6OnlyMismatch(host, true); | 140 negTestBindV6OnlyMismatch(host, true); |
122 negTestBindV6OnlyMismatch(host, false); | 141 negTestBindV6OnlyMismatch(host, false); |
123 | 142 |
124 testListenCloseListenClose(host); | 143 testListenCloseListenClose(host); |
125 } | 144 } |
126 | 145 asyncEnd(); |
127 asyncStart(); | |
128 testBindDifferentAddresses(InternetAddress.ANY_IP_V6, | |
129 InternetAddress.ANY_IP_V4, | |
130 true, | |
131 false).then((_) { | |
132 testBindDifferentAddresses(InternetAddress.ANY_IP_V4, | |
133 InternetAddress.ANY_IP_V6, | |
134 false, | |
135 true); | |
136 asyncEnd(); | |
137 }); | |
138 } | 146 } |
OLD | NEW |