Example usage for io.netty.channel.socket ChannelInputShutdownEvent INSTANCE

List of usage examples for io.netty.channel.socket ChannelInputShutdownEvent INSTANCE

Introduction

In this page you can find the example usage for io.netty.channel.socket ChannelInputShutdownEvent INSTANCE.

Prototype

ChannelInputShutdownEvent INSTANCE

To view the source code for io.netty.channel.socket ChannelInputShutdownEvent INSTANCE.

Click Source Link

Document

Instance to use

Usage

From source file:org.fusesource.hawtdispatch.netty.HawtSocketChannel.java

License:Apache License

private void onReadReady() {
    final ChannelPipeline pipeline = pipeline();
    final ByteBuf byteBuf = pipeline.inboundByteBuffer();
    boolean closed = false;
    boolean read = false;
    boolean firedInboundBufferSuspended = false;
    try {/*w  ww  .  jav a 2 s .  c  om*/
        expandReadBuffer(byteBuf);
        loop: for (;;) {

            int localReadAmount = byteBuf.writeBytes(javaChannel(), byteBuf.writableBytes());
            if (localReadAmount > 0) {
                read = true;
            } else if (localReadAmount < 0) {
                closed = true;
                break;
            }

            switch (expandReadBuffer(byteBuf)) {
            case 0:
                // Read all - stop reading.
                break loop;
            case 1:
                // Keep reading until everything is read.
                break;
            case 2:
                // Let the inbound handler drain the buffer and continue reading.
                if (read) {
                    read = false;
                    pipeline.fireInboundBufferUpdated();
                    if (!byteBuf.isWritable()) {
                        throw new IllegalStateException(
                                "an inbound handler whose buffer is full must consume at " + "least one byte.");
                    }
                }
            }
        }
    } catch (Throwable t) {
        if (read) {
            read = false;
            pipeline.fireInboundBufferUpdated();
        }

        if (t instanceof IOException) {
            closed = true;
        } else if (!closed) {
            firedInboundBufferSuspended = true;
            pipeline.fireChannelReadSuspended();
        }
        pipeline().fireExceptionCaught(t);
    } finally {
        if (read) {
            pipeline.fireInboundBufferUpdated();
        }

        if (closed) {
            setInputShutdown();
            if (isOpen()) {
                if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) {
                    pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE);
                } else {
                    close(newPromise());
                }
            }
        } else if (!firedInboundBufferSuspended) {
            pipeline.fireChannelReadSuspended();
        }

        if (!config().isAutoRead()) {
            readSource.suspend();
        }
    }
}