71
71
import static com .oracle .graal .python .runtime .PosixConstants .SO_DOMAIN ;
72
72
import static com .oracle .graal .python .runtime .PosixConstants .SO_PROTOCOL ;
73
73
import static com .oracle .graal .python .runtime .PosixConstants .SO_TYPE ;
74
+ import static com .oracle .graal .python .runtime .PosixConstants .TCP_NODELAY ;
74
75
import static com .oracle .graal .python .runtime .PosixConstants .TCP_USER_TIMEOUT ;
75
76
import static org .hamcrest .CoreMatchers .anyOf ;
76
77
import static org .hamcrest .CoreMatchers .equalTo ;
77
78
import static org .junit .Assert .assertArrayEquals ;
78
79
import static org .junit .Assert .assertEquals ;
79
80
import static org .junit .Assert .assertFalse ;
81
+ import static org .junit .Assert .assertNotEquals ;
80
82
import static org .junit .Assert .assertNull ;
81
83
import static org .junit .Assert .assertThat ;
82
84
import static org .junit .Assert .assertTrue ;
90
92
import java .util .stream .Collectors ;
91
93
import java .util .stream .Stream ;
92
94
95
+ import com .oracle .graal .python .runtime .PosixSupportLibrary .SelectResult ;
96
+ import com .oracle .graal .python .runtime .PosixSupportLibrary .Timeval ;
93
97
import org .hamcrest .Description ;
94
98
import org .hamcrest .TypeSafeMatcher ;
95
99
import org .junit .Before ;
@@ -531,6 +535,16 @@ public void setSocketOptions() throws PosixException {
531
535
assertEquals (newTimeout , getIntSockOpt (socket , IPPROTO_TCP .value , TCP_USER_TIMEOUT .getValueIfDefined ()));
532
536
}
533
537
538
+ @ Test
539
+ public void setSocketOptionsTcpNodelay () throws PosixException {
540
+ assumeTrue (TCP_NODELAY .defined );
541
+ TcpClient cli = new TcpClient (AF_INET .value );
542
+ setIntSockOpt (cli .fd , IPPROTO_TCP .value , TCP_NODELAY .getValueIfDefined (), 1 );
543
+ TcpServer srv = new TcpServer (AF_INET .value );
544
+ cli .connect (srv .usa ());
545
+ assertNotEquals (0 , getIntSockOpt (cli .fd , IPPROTO_TCP .value , TCP_NODELAY .getValueIfDefined ()));
546
+ }
547
+
534
548
@ Test
535
549
public void nonBlockingDgramRecv () throws PosixException {
536
550
expectErrno (OSErrorEnum .EWOULDBLOCK );
@@ -555,6 +569,55 @@ public void nonBlockingAccept() throws PosixException {
555
569
srv .accept (cli .address ());
556
570
}
557
571
572
+ @ Test
573
+ public void dgramSelect () throws PosixException {
574
+ UdpServer srv = new UdpServer (AF_INET .value );
575
+ UdpClient cli = new UdpClient (AF_INET .value );
576
+
577
+ SelectResult res = lib .select (posixSupport , new int []{srv .fd }, new int [0 ], new int [0 ], new Timeval (0 , 100000 ));
578
+ assertFalse (res .getReadFds ()[0 ]);
579
+
580
+ cli .sendto (DATA , 0 , srv .usa ());
581
+
582
+ res = lib .select (posixSupport , new int []{srv .fd }, new int [0 ], new int [0 ], new Timeval (0 , 100000 ));
583
+ assertTrue (res .getReadFds ()[0 ]);
584
+
585
+ checkUsa (cli .address (), srv .recvfrom (DATA , 0 ));
586
+ }
587
+
588
+ @ Test
589
+ public void streamSelect () throws PosixException {
590
+ TcpServer srv = new TcpServer (AF_INET .value );
591
+ TcpClient cli = new TcpClient (AF_INET .value );
592
+
593
+ SelectResult res = lib .select (posixSupport , new int []{srv .fd }, new int [0 ], new int [0 ], new Timeval (0 , 100000 ));
594
+ assertFalse (res .getReadFds ()[0 ]);
595
+
596
+ cli .connect (srv .usa ());
597
+
598
+ res = lib .select (posixSupport , new int []{srv .fd , cli .fd }, new int [0 ], new int [0 ], new Timeval (0 , 100000 ));
599
+ assertTrue (res .getReadFds ()[0 ]);
600
+ assertFalse (res .getReadFds ()[1 ]);
601
+
602
+ TcpClient c = srv .accept (cli .address ());
603
+
604
+ checkUsa (c .address (), cli .getpeername ());
605
+ checkUsa (cli .address (), c .getpeername ());
606
+
607
+ c .shutdown (SHUT_RD .value );
608
+
609
+ c .send (DATA , 0 );
610
+
611
+ res = lib .select (posixSupport , new int []{srv .fd , cli .fd , c .fd }, new int [0 ], new int [0 ], new Timeval (0 , 100000 ));
612
+ assertFalse (res .getReadFds ()[0 ]);
613
+ assertTrue (res .getReadFds ()[1 ]);
614
+ assertTrue (res .getReadFds ()[2 ]);
615
+
616
+ assertEquals (0 , lib .recv (posixSupport , c .fd , new byte [10 ], 0 , 10 , 0 ));
617
+
618
+ cli .recv (DATA , 0 );
619
+ }
620
+
558
621
@ Test
559
622
public void getnameinfo () throws GetAddrInfoException {
560
623
Object [] res = lib .getnameinfo (posixSupport , createUsa (new Inet6SockAddr (443 , IN6ADDR_LOOPBACK , 0 , 0 )), NI_NUMERICSERV .value | NI_NUMERICHOST .value );
0 commit comments