@@ -10,7 +10,7 @@ import "dart:io";
1010
1111import 'test_utils.dart' show retry, throws, withTempDir;
1212
13- Future testArguments (connectFunction, String socketDir ) async {
13+ Future testArguments (connectFunction) async {
1414 var sourceAddress;
1515 final serverIPv4 = await ServerSocket .bind (InternetAddress .loopbackIPv4, 0 );
1616 serverIPv4.listen ((_) {
@@ -22,12 +22,6 @@ Future testArguments(connectFunction, String socketDir) async {
2222 throw 'Unexpected connection from address $sourceAddress ' ;
2323 });
2424
25- ServerSocket serverUnix = await ServerSocket .bind (
26- InternetAddress ('$socketDir /sock' , type: InternetAddressType .unix), 0 );
27- serverUnix.listen ((_) {
28- throw 'Unexpected connection from address $sourceAddress ' ;
29- });
30-
3125 // Illegal type for sourceAddress.
3226 for (sourceAddress in ['www.google.com' , 'abc' ]) {
3327 await throws (
@@ -48,7 +42,7 @@ Future testArguments(connectFunction, String socketDir) async {
4842 for (sourceAddress in [
4943 '::1' ,
5044 InternetAddress .loopbackIPv6,
51- InternetAddress ('$ socketDir / sock' , type: InternetAddressType .unix)
45+ InternetAddress ('sock' , type: InternetAddressType .unix)
5246 ]) {
5347 await throws (
5448 () => connectFunction ('127.0.0.1' , serverIPv4.port,
@@ -59,13 +53,26 @@ Future testArguments(connectFunction, String socketDir) async {
5953 for (sourceAddress in [
6054 '127.0.0.1' ,
6155 InternetAddress .loopbackIPv4,
62- InternetAddress ('$ socketDir / sock' , type: InternetAddressType .unix)
56+ InternetAddress ('sock' , type: InternetAddressType .unix)
6357 ]) {
6458 await throws (
6559 () => connectFunction ('::1' , serverIPv6.port,
6660 sourceAddress: sourceAddress),
6761 (e) => e is SocketException );
6862 }
63+
64+ await serverIPv4.close ();
65+ await serverIPv6.close ();
66+ }
67+
68+ Future testUnixDomainArguments (connectFunction, String socketDir) async {
69+ var sourceAddress;
70+ final serverUnix = await ServerSocket .bind (
71+ InternetAddress ('$socketDir /sock' , type: InternetAddressType .unix), 0 );
72+ serverUnix.listen ((_) {
73+ throw 'Unexpected connection from address $sourceAddress ' ;
74+ });
75+
6976 // Address family mismatch for Unix domain sockets.
7077 for (sourceAddress in [
7178 '127.0.0.1' ,
@@ -82,8 +89,6 @@ Future testArguments(connectFunction, String socketDir) async {
8289 e is SocketException &&
8390 e.toString ().contains ('Address family not supported' ));
8491 }
85- await serverIPv4.close ();
86- await serverIPv6.close ();
8792 await serverUnix.close ();
8893}
8994
@@ -158,16 +163,24 @@ Future testConnect(InternetAddress bindAddress, bool v6Only,
158163
159164main () async {
160165 await retry (() async {
161- await withTempDir ('unix_socket_test' , (Directory dir) async {
162- await testArguments (RawSocket .connect, "${dir .path }" );
163- });
166+ await testArguments (RawSocket .connect);
164167 });
165168 await retry (() async {
166- await withTempDir ('unix_socket_test' , (Directory dir) async {
167- await testArguments (Socket .connect, "${dir .path }" );
168- });
169+ await testArguments (Socket .connect);
169170 });
170171
172+ if (Platform .isMacOS || Platform .isLinux || Platform .isAndroid) {
173+ await retry (() async {
174+ await withTempDir ('unix_socket_test' , (Directory dir) async {
175+ await testUnixDomainArguments (RawSocket .connect, "${dir .path }" );
176+ });
177+ });
178+ await retry (() async {
179+ await withTempDir ('unix_socket_test' , (Directory dir) async {
180+ await testUnixDomainArguments (Socket .connect, "${dir .path }" );
181+ });
182+ });
183+ }
171184 await retry (() async {
172185 await testConnect (
173186 InternetAddress .anyIPv4, false , RawSocket .connect, (s) => s.close ());
0 commit comments