io.netty.channel.socket.ChannelInputShutdownEvent Java Examples
The following examples show how to use
io.netty.channel.socket.ChannelInputShutdownEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractEpollChannel.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
/** * Shutdown the input side of the channel. */ // void shutdownInput(boolean rdHup) { if (!socket.isInputShutdown()) { if (isAllowHalfClosure(config())) { try { socket.shutdown(true, false); } catch (IOException ignored) { // We attempted to shutdown and failed, which means the input has already effectively been // shutdown. fireEventAndClose(ChannelInputShutdownEvent.INSTANCE); return; } catch (NotYetConnectedException ignore) { // We attempted to shutdown and failed, which means the input has already effectively been // shutdown. } clearEpollIn(); pipeline().fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { close(voidPromise()); } } else if (!rdHup) { inputClosedSeenErrorOnRead = true; pipeline().fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE); } }
Example #2
Source File: SocketShutdownOutputByPeerTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof ChannelInputShutdownEvent) { halfClosureCount.incrementAndGet(); halfClosure.countDown(); } }
Example #3
Source File: AbstractOioByteChannel.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private void closeOnRead(ChannelPipeline pipeline) { if (isOpen()) { if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) { shutdownInput(); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { unsafe().close(unsafe().voidPromise()); } } }
Example #4
Source File: AbstractNioByteChannel.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private void closeOnRead(ChannelPipeline pipeline) { if (!isInputShutdown0()) { if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) { shutdownInput(); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { close(voidPromise()); } } else { pipeline.fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE); } }
Example #5
Source File: ByteToMessageDecoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof ChannelInputShutdownEvent) { // The decodeLast method is invoked when a channelInactive event is encountered. // This method is responsible for ending requests in some situations and must be called // when the input has been shutdown. channelInputClosed(ctx, false); } super.userEventTriggered(ctx, evt); }
Example #6
Source File: ReplayingDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testChannelInputShutdownEvent() { final AtomicReference<Error> error = new AtomicReference<Error>(); EmbeddedChannel channel = new EmbeddedChannel(new ReplayingDecoder<Integer>(0) { private boolean decoded; @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (!(in instanceof ReplayingDecoderByteBuf)) { error.set(new AssertionError("in must be of type " + ReplayingDecoderByteBuf.class + " but was " + in.getClass())); return; } if (!decoded) { decoded = true; in.readByte(); state(1); } else { // This will throw an ReplayingError in.skipBytes(Integer.MAX_VALUE); } } }); assertFalse(channel.writeInbound(Unpooled.wrappedBuffer(new byte[] {0, 1}))); channel.pipeline().fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); assertFalse(channel.finishAndReleaseAll()); Error err = error.get(); if (err != null) { throw err; } }
Example #7
Source File: AbstractKQueueChannel.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Shutdown the input side of the channel. */ void shutdownInput(boolean readEOF) { // We need to take special care of calling finishConnect() if readEOF is true and we not // fullfilled the connectPromise yet. If we fail to do so the connectPromise will be failed // with a ClosedChannelException as a close() will happen and so the FD is closed before we // have a chance to call finishConnect() later on. Calling finishConnect() here will ensure // we observe the correct exception in case of a connect failure. if (readEOF && connectPromise != null) { finishConnect(); } if (!socket.isInputShutdown()) { if (isAllowHalfClosure(config())) { try { socket.shutdown(true, false); } catch (IOException ignored) { // We attempted to shutdown and failed, which means the input has already effectively been // shutdown. fireEventAndClose(ChannelInputShutdownEvent.INSTANCE); return; } catch (NotYetConnectedException ignore) { // We attempted to shutdown and failed, which means the input has already effectively been // shutdown. } pipeline().fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { close(voidPromise()); } } else if (!readEOF) { inputClosedSeenErrorOnRead = true; pipeline().fireUserEventTriggered(ChannelInputShutdownReadComplete.INSTANCE); } }
Example #8
Source File: ByteToMessageDecoder.java From servicetalk with Apache License 2.0 | 5 votes |
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof ChannelInputShutdownEvent) { ctxWrapper.setDelegate(ctx); // The decodeLast method is invoked when a channelInactive event is encountered. // This method is responsible for ending requests in some situations and must be called // when the input has been shutdown. channelInputClosed(ctxWrapper, false); } super.userEventTriggered(ctx, evt); }
Example #9
Source File: RequestResponseCloseHandlerTest.java From servicetalk with Apache License 2.0 | 5 votes |
private ServerSocketChannel startServer() { EventLoopAwareNettyIoExecutor eventLoopAwareNettyIoExecutor = toEventLoopAwareNettyIoExecutor(S_CTX.ioExecutor()); EventLoop loop = eventLoopAwareNettyIoExecutor.eventLoopGroup().next(); ServerBootstrap bs = new ServerBootstrap(); bs.group(loop); bs.channel(serverChannel(loop, InetSocketAddress.class)); bs.childHandler(new ChannelInitializer() { @Override protected void initChannel(final Channel ch) { sChannel = (SocketChannel) ch; ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { @Override public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) { LOGGER.debug("Server Evt: {}", evt.getClass().getSimpleName()); if (evt == ChannelInputShutdownEvent.INSTANCE) { serverInputShutdownLatch.countDown(); } else if (evt == ChannelInputShutdownReadComplete.INSTANCE) { serverInputShutdownReadCompleteLatch.countDown(); } else if (evt == ChannelOutputShutdownEvent.INSTANCE) { serverOutputShutdownLatch.countDown(); } release(evt); } }); ch.eventLoop().execute(connectedLatch::countDown); } }); bs.childOption(AUTO_READ, true); bs.childOption(ALLOW_HALF_CLOSURE, true); bs.childOption(AUTO_CLOSE, false); return (ServerSocketChannel) bs.bind(localAddress(0)) .syncUninterruptibly().channel(); }
Example #10
Source File: RequestResponseCloseHandlerTest.java From servicetalk with Apache License 2.0 | 5 votes |
private SocketChannel connectClient(InetSocketAddress address) { EventLoopAwareNettyIoExecutor eventLoopAwareNettyIoExecutor = toEventLoopAwareNettyIoExecutor(C_CTX.ioExecutor()); EventLoop loop = eventLoopAwareNettyIoExecutor.eventLoopGroup().next(); Bootstrap bs = new Bootstrap(); bs.group(loop); bs.channel(socketChannel(loop, InetSocketAddress.class)); bs.handler(new ChannelInitializer() { @Override protected void initChannel(final Channel ch) { ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { @Override public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) { LOGGER.debug("Client Evt: {}", evt.getClass().getSimpleName()); if (evt == ChannelInputShutdownEvent.INSTANCE) { clientInputShutdownLatch.countDown(); } else if (evt == ChannelInputShutdownReadComplete.INSTANCE) { clientInputShutdownReadCompleteLatch.countDown(); } else if (evt == ChannelOutputShutdownEvent.INSTANCE) { clientOutputShutdownLatch.countDown(); } release(evt); } }); } }); bs.option(AUTO_READ, true); bs.option(ALLOW_HALF_CLOSURE, true); bs.option(AUTO_CLOSE, false); return (SocketChannel) bs.connect(address).syncUninterruptibly().channel(); }
Example #11
Source File: SocketShutdownOutputByPeerTest.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof ChannelInputShutdownEvent) { halfClosureCount.incrementAndGet(); halfClosure.countDown(); } }
Example #12
Source File: AbstractNioByteChannel.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
private void closeOnRead(ChannelPipeline pipeline) { SelectionKey key = selectionKey(); setInputShutdown(); if (isOpen()) { if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) { key.interestOps(key.interestOps() & ~readInterestOp); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { close(voidPromise()); } } }
Example #13
Source File: AbstractEpollStreamChannel.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
private void closeOnRead(ChannelPipeline pipeline) { inputShutdown = true; if (isOpen()) { if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) { clearEpollIn0(); pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE); } else { close(voidPromise()); } } }