DotNetty.Handlers The {@link FlowControlHandler} ensures that only one message per {@code read()} is sent downstream. Classes such as {@link ByteToMessageDecoder} or {@link MessageToByteEncoder} are free to emit as many events as they like for any given input. A channel's auto reading configuration doesn't usually apply in these scenarios. This is causing problems in downstream {@link ChannelHandler}s that would like to hold subsequent events while they're processing one event. It's a common problem with the {@code HttpObjectDecoder} that will very often fire a {@code HttpRequest} that is immediately followed by a {@code LastHttpContent} event.
{@code
             ChannelPipeline pipeline = ...;
            
             pipeline.addLast(new HttpServerCodec());
             pipeline.addLast(new FlowControlHandler());
            
             pipeline.addLast(new MyExampleHandler());
            
             class MyExampleHandler extends ChannelInboundHandlerAdapter {
               @Override
               public void channelRead(IChannelHandlerContext ctx, Object msg) {
                 if (msg instanceof HttpRequest) {
                   ctx.channel().config().setAutoRead(false);
            
                   // The FlowControlHandler will hold any subsequent events that
                   // were emitted by HttpObjectDecoder until auto reading is turned
                   // back on or Channel#read() is being called.
                 }
               }
             }
             }
@see ChannelConfig#setAutoRead(bool)
Determine if the underlying {@link Queue} is empty. This method exists for testing, debugging and inspection purposes and it is not Thread safe! Releases all messages and destroys the {@link Queue}. Dequeues one or many (or none) messages depending on the channel's auto reading state and returns the number of messages that were consumed from the internal queue. The {@code minConsume} argument is used to force {@code dequeue()} into consuming that number of messages regardless of the channel's auto reading configuration. @see #read(ChannelHandlerContext) @see #channelRead(ChannelHandlerContext, Object) A that logs all events using a logging framework. By default, all events are logged at DEBUG level. Creates a new instance whose logger name is the fully qualified class name of the instance with hex dump enabled. Creates a new instance whose logger name is the fully qualified class name of the instance the log level Creates a new instance with the specified logger name and with hex dump enabled the class type to generate the logger for Creates a new instance with the specified logger name. the class type to generate the logger for the log level Creates a new instance with the specified logger name using the default log level. the name of the class to use for the logger Creates a new instance with the specified logger name. the name of the class to use for the logger the log level Returns the that this handler uses to log Formats an event and returns the formatted message the name of the event Formats an event and returns the formatted message. the name of the event the argument of the event Formats an event and returns the formatted message. This method is currently only used for formatting the name of the event the first argument of the event the second argument of the event Generates the default log message of the specified event whose argument is a . Generates the default log message of the specified event whose argument is a . Generates the default log message of the specified event whose argument is an arbitrary object. An that represents the idle state of a . No data was received for a while. No data was sent for a while. No data was either received or sent for a while. A user event triggered by when a is idle. Constructor for sub-classes. the which triggered the event. true if its the first idle event for the . Returns the idle state. The state. Returns true if this was the first event for the true if first; otherwise, false. Triggers an when a has not performed read, write, or both operation for a while.

Supported idle states

PropertyMeaning
readerIdleTime an whose state is will be triggered when no read was performed for the specified period of time. Specify 0 to disable.
writerIdleTime an whose state is will be triggered when no write was performed for the specified period of time. Specify 0 to disable.
allIdleTime an whose state is will be triggered when neither read nor write was performed for the specified period of time. Specify 0 to disable.
An example that sends a ping message when there is no outbound traffic for 30 seconds. The connection is closed when there is no inbound traffic for 60 seconds. var bootstrap = new (); bootstrap.ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast("idleStateHandler", new (60, 30, 0); pipeline.AddLast("myHandler", new MyHandler()); } Handler should handle the triggered by . public class MyHandler : ChannelDuplexHandler { public override void UserEventTriggered( context, evt) { if(evt is ) { e = () evt; if (e.State == .ReaderIdle) { ctx.close(); } else if(e.State == .WriterIdle) { ctx.writeAndFlush(new PingMessage()); } } } }
Initializes a new instance firing s. an whose state is will be triggered when no read was performed for the specified period of time. Specify 0 to disable. an whose state is will be triggered when no write was performed for the specified period of time. Specify 0 to disable. an whose state is will be triggered when neither read nor write was performed for the specified period of time. Specify 0 to disable. Initializes a new instance firing s. whether or not the consumption of bytes should be taken into consideration when assessing write idleness. The default is false. an whose state is will be triggered when no read was performed for the specified period of time. Specify to disable. an whose state is will be triggered when no write was performed for the specified period of time. Specify to disable. an whose state is will be triggered when neither read nor write was performed for the specified period of time. Specify to disable. Return the readerIdleTime that was given when instance this class in milliseconds. The reader idle time in millis. Return the writerIdleTime that was given when instance this class in milliseconds. The writer idle time in millis. Return the allIdleTime that was given when instance this class in milliseconds. The all idle time in millis. This method is visible for testing! This method is visible for testing! Is called when an should be fired. This implementation calls . Context. Evt. Returns a . Returns true if and only if the was constructed with observeOutput enabled and there has been an observed change in the between two consecutive calls of this method. https://github.com/netty/netty/issues/6150 Raises a when no data was read within a certain period of time.
             The connection is closed when there is no inbound traffic
             for 30 seconds.
            
             
             
             var bootstrap = new ();
            
             bootstrap.ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel =>
             {
                 IChannelPipeline pipeline = channel.Pipeline;
                 
                 pipeline.AddLast("readTimeoutHandler", new (30);
                 pipeline.AddLast("myHandler", new MyHandler());
             } 
             
                        
             
             public class MyHandler : ChannelDuplexHandler 
             {
                 public override void ExceptionCaught( context,  exception)
                 {
                     if(exception is ) 
                     {
                         // do somethind
                     }
                     else
                     {
                         base.ExceptionCaught(context, cause);
                     }
                  }
             }
             
             
             
Initializes a new instance of the class. Timeout in seconds. Initializes a new instance of the class. Timeout. Is called when a read timeout was detected. Context. Raises a when a write operation cannot finish in a certain period of time. The connection is closed when a write operation cannot finish in 30 seconds. var bootstrap = new (); bootstrap.ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel => { IChannelPipeline pipeline = channel.Pipeline; pipeline.AddLast("writeTimeoutHandler", new (30); pipeline.AddLast("myHandler", new MyHandler()); } public class MyHandler : ChannelDuplexHandler { public override void ExceptionCaught( context, exception) { if(exception is ) { // do somethind } else { base.ExceptionCaught(context, cause); } } } A doubly-linked list to track all WriteTimeoutTasks. Initializes a new instance of the class. Timeout in seconds. Initializes a new instance of the class. Timeout. Is called when a write timeout was detected Context. Special exception which will get thrown if a packet is received that not looks like a TLS/SSL record. A user can check for this and so detect if one peer tries to use secure and the other plain connection. Unwraps inbound SSL records. Creates a new event that indicates a successful handshake. Creates a new event that indicates an unsuccessful handshake. Use {@link #SUCCESS} to indicate a successful handshake. Return {@code true} if the handshake was successful Return the {@link Throwable} if {@link #isSuccess()} returns {@code false} and so the handshake failed. Utilities for TLS packets. change cipher spec alert handshake application data the length of the ssl record header (in bytes) Return how much bytes can be read out of the encrypted data. Be aware that this method will not increase the readerIndex of the given . The to read from. Be aware that it must have at least bytes to read, otherwise it will throw an . Offset to record start. The length of the encrypted packet that is included in the buffer. This will return -1 if the given is not encrypted at all.