static void HandleWriteTimeout(IdleStateHandler self, IChannelHandlerContext context)
        {
            TimeSpan lastWriteTime = self.lastWriteTime;
            TimeSpan nextDelay     = self.writerIdleTime - (self.Ticks() - lastWriteTime);

            if (nextDelay.Ticks <= 0)
            {
                // Writer is idle - set a new timeout and notify the callback.
                self.writerIdleTimeout = self.Schedule(context, WriteTimeoutAction, self, context,
                                                       self.writerIdleTime);

                bool first = self.firstWriterIdleEvent;
                self.firstWriterIdleEvent = false;

                try
                {
                    if (self.HasOutputChanged(context, first))
                    {
                        return;
                    }

                    IdleStateEvent stateEvent = self.NewIdleStateEvent(IdleState.WriterIdle, first);
                    self.ChannelIdle(context, stateEvent);
                }
                catch (Exception ex)
                {
                    context.FireExceptionCaught(ex);
                }
            }
            else
            {
                // Write occurred before the timeout - set a new timeout with shorter delay.
                self.writerIdleTimeout = self.Schedule(context, WriteTimeoutAction, self, context, nextDelay);
            }
        }
示例#2
0
        static void HandleAllTimeout(IdleStateHandler self, IChannelHandlerContext context)
        {
            TimeSpan nextDelay = self._allIdleTime;

            if (!self._reading)
            {
                nextDelay -= self.Ticks() - TimeUtil.Max(self._lastReadTime, self._lastWriteTime);
            }

            if (nextDelay.Ticks <= 0)
            {
                // Both reader and writer are idle - set a new timeout and
                // notify the callback.
                self._allIdleTimeout = self.Schedule(context, AllTimeoutAction, self, context,
                                                     self._allIdleTime);

                bool first = self._firstAllIdleEvent;
                self._firstAllIdleEvent = false;

                try
                {
                    if (self.HasOutputChanged(context, first))
                    {
                        return;
                    }

                    IdleStateEvent stateEvent = self.NewIdleStateEvent(IdleState.AllIdle, first);
                    self.ChannelIdle(context, stateEvent);
                }
                catch (Exception ex)
                {
                    _ = context.FireExceptionCaught(ex);
                }
            }
            else
            {
                // Either read or write occurred before the timeout - set a new
                // timeout with shorter delay.
                self._allIdleTimeout = self.Schedule(context, AllTimeoutAction, self, context, nextDelay);
            }
        }