7171import static com .oracle .graal .python .runtime .PosixConstants .SO_DOMAIN ;
7272import static com .oracle .graal .python .runtime .PosixConstants .SO_PROTOCOL ;
7373import static com .oracle .graal .python .runtime .PosixConstants .SO_TYPE ;
74+ import static com .oracle .graal .python .runtime .PosixConstants .TCP_NODELAY ;
7475import static com .oracle .graal .python .runtime .PosixConstants .TCP_USER_TIMEOUT ;
7576import static org .hamcrest .CoreMatchers .anyOf ;
7677import static org .hamcrest .CoreMatchers .equalTo ;
7778import static org .junit .Assert .assertArrayEquals ;
7879import static org .junit .Assert .assertEquals ;
7980import static org .junit .Assert .assertFalse ;
81+ import static org .junit .Assert .assertNotEquals ;
8082import static org .junit .Assert .assertNull ;
8183import static org .junit .Assert .assertThat ;
8284import static org .junit .Assert .assertTrue ;
9092import java .util .stream .Collectors ;
9193import java .util .stream .Stream ;
9294
95+ import com .oracle .graal .python .runtime .PosixSupportLibrary .SelectResult ;
96+ import com .oracle .graal .python .runtime .PosixSupportLibrary .Timeval ;
9397import org .hamcrest .Description ;
9498import org .hamcrest .TypeSafeMatcher ;
9599import org .junit .Before ;
@@ -531,6 +535,16 @@ public void setSocketOptions() throws PosixException {
531535 assertEquals (newTimeout , getIntSockOpt (socket , IPPROTO_TCP .value , TCP_USER_TIMEOUT .getValueIfDefined ()));
532536 }
533537
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+
534548 @ Test
535549 public void nonBlockingDgramRecv () throws PosixException {
536550 expectErrno (OSErrorEnum .EWOULDBLOCK );
@@ -555,6 +569,55 @@ public void nonBlockingAccept() throws PosixException {
555569 srv .accept (cli .address ());
556570 }
557571
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+
558621 @ Test
559622 public void getnameinfo () throws GetAddrInfoException {
560623 Object [] res = lib .getnameinfo (posixSupport , createUsa (new Inet6SockAddr (443 , IN6ADDR_LOOPBACK , 0 , 0 )), NI_NUMERICSERV .value | NI_NUMERICHOST .value );
0 commit comments