@@ -180,6 +180,187 @@ Future testExistingFile(String name) async {
180
180
Expect .fail ("bind should fail with existing file" );
181
181
}
182
182
183
+ Future testSetSockOpt (String name) async {
184
+ var address = InternetAddress ('$name /sock' , type: InternetAddressType .unix);
185
+ var server = await ServerSocket .bind (address, 0 , shared: false );
186
+
187
+ var sub;
188
+ sub = server.listen ((s) {
189
+ sub.cancel ();
190
+ server.close ();
191
+ });
192
+
193
+ var socket = await Socket .connect (address, server.port);
194
+ socket.write (" socket content" );
195
+
196
+ // Get some socket options.
197
+ for (int i = 0 ; i < 5 ; i++ ) {
198
+ try {
199
+ RawSocketOption option =
200
+ RawSocketOption .fromBool (RawSocketOption .levelTcp, i, false );
201
+ var result = socket.getRawOption (option);
202
+ } catch (e) {
203
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
204
+ }
205
+ }
206
+
207
+ for (int i = 0 ; i < 5 ; i++ ) {
208
+ try {
209
+ RawSocketOption option =
210
+ RawSocketOption .fromBool (RawSocketOption .levelUdp, i, false );
211
+ var result = socket.getRawOption (option);
212
+ } catch (e) {
213
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
214
+ }
215
+ }
216
+
217
+ for (int i = 0 ; i < 5 ; i++ ) {
218
+ try {
219
+ RawSocketOption option =
220
+ RawSocketOption .fromBool (RawSocketOption .levelIPv4, i, false );
221
+ var result = socket.getRawOption (option);
222
+ } catch (e) {
223
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
224
+ }
225
+ }
226
+
227
+ for (int i = 0 ; i < 5 ; i++ ) {
228
+ try {
229
+ RawSocketOption option =
230
+ RawSocketOption .fromBool (RawSocketOption .levelIPv6, i, false );
231
+ var result = socket.getRawOption (option);
232
+ } catch (e) {
233
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
234
+ }
235
+ }
236
+
237
+ for (int i = 0 ; i < 5 ; i++ ) {
238
+ try {
239
+ RawSocketOption option =
240
+ RawSocketOption .fromBool (RawSocketOption .levelSocket, i, false );
241
+ var result = socket.getRawOption (option);
242
+ } catch (e) {
243
+ Expect .isTrue (e.toString ().contains ('Protocol not available' ));
244
+ }
245
+ }
246
+
247
+ for (int i = 0 ; i < 5 ; i++ ) {
248
+ try {
249
+ RawSocketOption option = RawSocketOption .fromBool (
250
+ RawSocketOption .IPv4MulticastInterface , i, false );
251
+ var result = socket.getRawOption (option);
252
+ } catch (e) {
253
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
254
+ }
255
+ }
256
+
257
+ for (int i = 0 ; i < 5 ; i++ ) {
258
+ try {
259
+ RawSocketOption option = RawSocketOption .fromBool (
260
+ RawSocketOption .IPv6MulticastInterface , i, false );
261
+ var result = socket.getRawOption (option);
262
+ } catch (e) {
263
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
264
+ }
265
+ }
266
+
267
+ // Set some socket options
268
+ try {
269
+ socket.setOption (SocketOption .tcpNoDelay, true );
270
+ } catch (e) {
271
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
272
+ }
273
+
274
+ for (int i = 0 ; i < 5 ; i++ ) {
275
+ try {
276
+ RawSocketOption option =
277
+ RawSocketOption .fromBool (RawSocketOption .levelTcp, i, false );
278
+ var result = socket.setRawOption (option);
279
+ } catch (e) {
280
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
281
+ }
282
+ }
283
+
284
+ for (int i = 0 ; i < 5 ; i++ ) {
285
+ try {
286
+ RawSocketOption option =
287
+ RawSocketOption .fromBool (RawSocketOption .levelUdp, i, false );
288
+ var result = socket.setRawOption (option);
289
+ } catch (e) {
290
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
291
+ }
292
+ }
293
+
294
+ for (int i = 0 ; i < 5 ; i++ ) {
295
+ try {
296
+ RawSocketOption option =
297
+ RawSocketOption .fromBool (RawSocketOption .levelIPv4, i, false );
298
+ var result = socket.setRawOption (option);
299
+ } catch (e) {
300
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
301
+ }
302
+ }
303
+
304
+ for (int i = 0 ; i < 5 ; i++ ) {
305
+ try {
306
+ RawSocketOption option =
307
+ RawSocketOption .fromBool (RawSocketOption .levelIPv6, i, false );
308
+ var result = socket.setRawOption (option);
309
+ } catch (e) {
310
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
311
+ }
312
+ }
313
+
314
+ for (int i = 0 ; i < 5 ; i++ ) {
315
+ try {
316
+ RawSocketOption option =
317
+ RawSocketOption .fromBool (RawSocketOption .levelSocket, i, false );
318
+ var result = socket.setRawOption (option);
319
+ } catch (e) {
320
+ Expect .isTrue (e.toString ().contains ('Protocol not available' ));
321
+ }
322
+ }
323
+
324
+ for (int i = 0 ; i < 5 ; i++ ) {
325
+ try {
326
+ RawSocketOption option = RawSocketOption .fromBool (
327
+ RawSocketOption .IPv4MulticastInterface , i, false );
328
+ var result = socket.setRawOption (option);
329
+ } catch (e) {
330
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
331
+ }
332
+ }
333
+
334
+ for (int i = 0 ; i < 5 ; i++ ) {
335
+ try {
336
+ RawSocketOption option = RawSocketOption .fromBool (
337
+ RawSocketOption .IPv6MulticastInterface , i, false );
338
+ var result = socket.setRawOption (option);
339
+ } catch (e) {
340
+ Expect .isTrue (e.toString ().contains ('Operation not supported' ));
341
+ }
342
+ }
343
+
344
+ socket.destroy ();
345
+ await server.close ();
346
+ }
347
+
348
+ Future testHttpServer (String name) async {
349
+ var address = InternetAddress ('$name /sock' , type: InternetAddressType .unix);
350
+ var httpServer = await HttpServer .bind (address, 0 );
351
+
352
+ var sub;
353
+ sub = httpServer.listen ((s) {
354
+ sub.cancel ();
355
+ httpServer.close ();
356
+ });
357
+
358
+ var socket = await Socket .connect (address, httpServer.port);
359
+
360
+ socket.destroy ();
361
+ await httpServer.close ();
362
+ }
363
+
183
364
// Create socket in temp directory
184
365
Future withTempDir (String prefix, Future <void > test (Directory dir)) async {
185
366
var tempDir = Directory .systemTemp.createTempSync (prefix);
@@ -211,6 +392,12 @@ void main() async {
211
392
await withTempDir ('unix_socket_test' , (Directory dir) async {
212
393
await testExistingFile ('${dir .path }' );
213
394
});
395
+ await withTempDir ('unix_socket_test' , (Directory dir) async {
396
+ await testSetSockOpt ('${dir .path }' );
397
+ });
398
+ await withTempDir ('unix_socket_test' , (Directory dir) async {
399
+ await testHttpServer ('${dir .path }' );
400
+ });
214
401
} catch (e) {
215
402
if (Platform .isMacOS || Platform .isLinux || Platform .isAndroid) {
216
403
Expect .fail ("Unexpected exception $e is thrown" );
0 commit comments