// Find an availble test port and bind to it.
boolean socketBound = false;
boolean datagramBound = false;
final SocketAcceptor acceptor = ( SocketAcceptor ) registry.getAcceptor( TransportType.SOCKET );
acceptor.setReuseAddress( true );
// Let's start from port #1 to detect possible resource leak
// because test will fail in port 1-1023 if user run this test
// as a normal user.
for( port = 1; port <= 65535; port ++ )
{
socketBound = false;
datagramBound = false;
Service socketService = new Service( "echo", TransportType.SOCKET, port );
Service datagramService = new Service( "echo", TransportType.DATAGRAM, port );
try
{
registry.bind( socketService, new EchoProtocolHandler()
{
// This is for TLS reentrance test
public void messageReceived( IoSession session, Object message ) throws Exception
{
if( !( message instanceof ByteBuffer ) )
{
return;
}
ByteBuffer buf = ( ByteBuffer ) message;
if( buf.remaining() == 1 && buf.get() == ( byte ) '.' )
{
SessionLog.info( session, "TLS Reentrance" );
( ( SSLFilter ) acceptor.getFilterChain().get( "SSL" ) ).startSSL( session );
// Send a response
buf = ByteBuffer.allocate( 1 );
buf.put( ( byte ) '.' );
buf.flip();