@@ -436,25 +436,62 @@ public static SixModelObject socket(long listener, ThreadContext tc) {
436
436
return h ;
437
437
}
438
438
439
- public static SixModelObject connect (SixModelObject obj , String host , long port , ThreadContext tc ) {
439
+ public static final int SOCKET_FAMILY_UNSPEC = 0 ;
440
+ public static final int SOCKET_FAMILY_INET = 1 ;
441
+ public static final int SOCKET_FAMILY_INET6 = 2 ;
442
+ public static final int SOCKET_FAMILY_UNIX = 3 ;
443
+
444
+ public static SixModelObject connect (SixModelObject obj , String host , long port , long family , ThreadContext tc ) {
440
445
IOHandleInstance h = (IOHandleInstance )obj ;
441
- if (h .handle instanceof SocketHandle ) {
442
- ((SocketHandle )h .handle ).connect (tc , host , (int ) port );
443
- } else {
444
- ExceptionHandling .dieInternal (tc ,
445
- "This handle does not support connect" );
446
- }
446
+
447
+ switch ((int ) family ) {
448
+ case SOCKET_FAMILY_UNSPEC :
449
+ case SOCKET_FAMILY_INET :
450
+ case SOCKET_FAMILY_INET6 :
451
+ if (h .handle instanceof SocketHandle ) {
452
+ ((SocketHandle )h .handle ).connect (tc , host , (int ) port );
453
+ } else {
454
+ ExceptionHandling .dieInternal (tc ,
455
+ "This handle does not support connect" );
456
+ }
457
+ break ;
458
+ case SOCKET_FAMILY_UNIX :
459
+ ExceptionHandling .dieInternal (tc ,
460
+ "UNIX sockets are not supported on the JVM" );
461
+ break ;
462
+ default :
463
+ ExceptionHandling .dieInternal (tc ,
464
+ "Unsupported socket family: " + Long .toString (family ));
465
+ break ;
466
+ }
467
+
447
468
return obj ;
448
469
}
449
470
450
- public static SixModelObject bindsock (SixModelObject obj , String host , long port , long backlog , ThreadContext tc ) {
471
+ public static SixModelObject bindsock (SixModelObject obj , String host , long port , long family , long backlog , ThreadContext tc ) {
451
472
IOHandleInstance h = (IOHandleInstance )obj ;
452
- if (h .handle instanceof IIOBindable ) {
453
- ((IIOBindable )h .handle ).bind (tc , host , (int ) port , (int )backlog );
454
- } else {
455
- ExceptionHandling .dieInternal (tc ,
456
- "This handle does not support bind" );
457
- }
473
+
474
+ switch ((int ) family ) {
475
+ case SOCKET_FAMILY_UNSPEC :
476
+ case SOCKET_FAMILY_INET :
477
+ case SOCKET_FAMILY_INET6 :
478
+ if (h .handle instanceof IIOBindable ) {
479
+ ((IIOBindable )h .handle ).bind (tc , host , (int ) port , (int ) backlog );
480
+ } else {
481
+ ExceptionHandling .dieInternal (tc ,
482
+ "This handle does not support bind" );
483
+ }
484
+ break ;
485
+ case SOCKET_FAMILY_UNIX :
486
+ ExceptionHandling .dieInternal (tc ,
487
+ "UNIX sockets are not supported on the JVM" );
488
+ break ;
489
+ default :
490
+ ExceptionHandling .dieInternal (tc ,
491
+ "Unsupported socket family: " + Long .toString (family ));
492
+ break ;
493
+ }
494
+
458
495
return obj ;
459
496
}
460
497
0 commit comments