@Override public boolean apply(SocketChannel input) { return input.isOpen(); } };
@Override public boolean apply(SocketChannel input) { return input.isOpen() && input.remoteAddress() != null && addresses.contains(input.remoteAddress()); } }));
@Override public boolean isClosed() { return !ch.isOpen(); }
@Override public boolean apply(SocketChannel input) { return input.isOpen(); } };
@Override public boolean apply(SocketChannel input) { return input.isOpen() && input.remoteAddress() != null && addresses.contains(input.remoteAddress()); } }));
public void testShutdownOutput(ServerBootstrap sb) throws Throwable { TestHandler h = new TestHandler(); Socket s = new Socket(); Channel sc = null; try { sc = sb.childHandler(h).childOption(ChannelOption.ALLOW_HALF_CLOSURE, true).bind().sync().channel(); SocketUtils.connect(s, sc.localAddress(), 10000); s.getOutputStream().write(1); assertEquals(1, (int) h.queue.take()); assertTrue(h.ch.isOpen()); assertTrue(h.ch.isActive()); assertFalse(h.ch.isInputShutdown()); assertFalse(h.ch.isOutputShutdown()); s.shutdownOutput(); h.halfClosure.await(); assertTrue(h.ch.isOpen()); assertTrue(h.ch.isActive()); assertTrue(h.ch.isInputShutdown()); assertFalse(h.ch.isOutputShutdown()); assertEquals(1, h.closure.getCount()); Thread.sleep(100); assertEquals(1, h.halfClosureCount.intValue()); } finally { if (sc != null) { sc.close(); } s.close(); } }
public void testShutdownOutputWithoutOption(ServerBootstrap sb) throws Throwable { TestHandler h = new TestHandler(); Socket s = new Socket(); Channel sc = null; try { sc = sb.childHandler(h).bind().sync().channel(); SocketUtils.connect(s, sc.localAddress(), 10000); s.getOutputStream().write(1); assertEquals(1, (int) h.queue.take()); assertTrue(h.ch.isOpen()); assertTrue(h.ch.isActive()); assertFalse(h.ch.isInputShutdown()); assertFalse(h.ch.isOutputShutdown()); s.shutdownOutput(); h.closure.await(); assertFalse(h.ch.isOpen()); assertFalse(h.ch.isActive()); assertTrue(h.ch.isInputShutdown()); assertTrue(h.ch.isOutputShutdown()); assertEquals(1, h.halfClosure.getCount()); Thread.sleep(100); assertEquals(0, h.halfClosureCount.intValue()); } finally { if (sc != null) { sc.close(); } s.close(); } }
/** * schedules the handshake initiation after the connection attempt */ private void scheduleHandshake( SocketChannel ch, HandshakeClient handshakeClient, TimeoutStrategy.Timeout handshakeDelay ) { ch.eventLoop().schedule( () -> { if ( ch.isActive() ) { initiateHandshake( ch, handshakeClient ); } else if ( ch.isOpen() ) { handshakeDelay.increment(); scheduleHandshake( ch, handshakeClient, handshakeDelay ); } else { handshakeClient.failIfNotDone( "Channel closed" ); } }, handshakeDelay.getMillis(), MILLISECONDS ); }