예제 #1
0
 private static void ReadIfNeeded(IChannelHandlerContext ctx)
 {
     if (!ctx.Channel.Configuration.AutoRead)
     {
         ctx.Read();
     }
 }
예제 #2
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            this.capturedContext = context;

            this.publishProcessors = new Dictionary <IMessagingServiceClient, MessageAsyncProcessor <PublishPacket> >(1);

            TimeSpan?ackTimeout = this.settings.DeviceReceiveAckCanTimeout ? this.settings.DeviceReceiveAckTimeout : (TimeSpan?)null;

            this.publishPubAckProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishAsync, this.RetransmitNextPublish, ackTimeout);
            this.publishPubAckProcessor.Completion.OnFault(ShutdownOnPubAckFaultAction);
            this.publishPubRecProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishReceiveAsync, this.RetransmitNextPublish, ackTimeout);
            this.publishPubRecProcessor.Completion.OnFault(ShutdownOnPubRecFaultAction);
            this.pubRelPubCompProcessor = new RequestAckPairProcessor <CompletionPendingMessageState, PubRelPacket>(this.AcknowledgePublishCompleteAsync, this.RetransmitNextPublishRelease, ackTimeout);
            this.pubRelPubCompProcessor.Completion.OnFault(ShutdownOnPubCompFaultAction);

            this.stateFlags = StateFlags.WaitingForConnect;
            TimeSpan?timeout = this.settings.ConnectArrivalTimeout;

            if (timeout.HasValue)
            {
                context.Executor.ScheduleAsync(CheckConnectTimeoutCallback, context, timeout.Value);
            }
            base.ChannelActive(context);

            context.Read();
        }
        public override void ChannelActive(IChannelHandlerContext context)
        {
            this.capturedContext = context;

            this.publishProcessors = new Dictionary <IMessagingServiceClient, MessageAsyncProcessor <PublishPacket> >(1);

            bool abortOnOutOfOrderAck = this.settings.AbortOnOutOfOrderPubAck;

            this.publishPubAckProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishAsync, abortOnOutOfOrderAck, this);
            this.publishPubAckProcessor.Closed.OnFault(ShutdownOnPubAckFaultAction, this);
            this.publishPubRecProcessor = new RequestAckPairProcessor <AckPendingMessageState, PublishPacket>(this.AcknowledgePublishReceiveAsync, abortOnOutOfOrderAck, this);
            this.publishPubRecProcessor.Closed.OnFault(ShutdownOnPubRecFaultAction, this);
            this.pubRelPubCompProcessor = new RequestAckPairProcessor <CompletionPendingMessageState, PubRelPacket>(this.AcknowledgePublishCompleteAsync, abortOnOutOfOrderAck, this);
            this.pubRelPubCompProcessor.Closed.OnFault(ShutdownOnPubCompFaultAction, this);

            this.stateFlags = StateFlags.WaitingForConnect;
            TimeSpan?timeout = this.settings.ConnectArrivalTimeout;

            if (timeout.HasValue)
            {
                context.Executor.ScheduleAsync(CheckConnectTimeoutCallback, context, timeout.Value);
            }
            base.ChannelActive(context);

            context.Read();
        }
예제 #4
0
        private async void Select(IChannelHandlerContext context, string hostName)
        {
            if (hostName is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.hostName);
            }

            ReleaseHandshakeBuffer();

            _suppressRead = true;
            try
            {
                var serverTlsSetting = await _serverTlsSniSettings.ServerTlsSettingMap(hostName);

                ReplaceHandler(context, serverTlsSetting);
            }
            catch (Exception ex)
            {
                ExceptionCaught(context, new DecoderException($"failed to get the server TLS setting for {hostName}, {ex}"));
            }
            finally
            {
                _suppressRead = false;
                if (_readPending)
                {
                    _readPending = false;
                    _            = context.Read();
                }
            }
        }
 public override void ChannelActive(IChannelHandlerContext ctx)
 {
     if (!ctx.Channel.Configuration.AutoRead)
     {
         ctx.Read();
     }
 }
예제 #6
0
 protected static void ReadIfNeeded(IChannelHandlerContext ctx)
 {
     if (!ctx.Channel.Configuration.IsAutoRead)
     {
         _ = ctx.Read();
     }
 }
 void ResumeReadingIfNecessary(IChannelHandlerContext context)
 {
     if (this.InboundBacklogSize == this.mqttTransportSettings.MaxPendingInboundMessages - 1) // we picked up a packet from full queue - now we have more room so order another read
     {
         context.Read();
     }
 }
예제 #8
0
 /// <inheritdoc />
 public override void Read(IChannelHandlerContext ctx)
 {
     if (Logger.IsEnabled(MsLogLevel.Trace))
     {
         Logger.LogTrace("Channel {0} reading", ctx.Channel);
     }
     ctx.Read();
 }
예제 #9
0
 public override void Read(IChannelHandlerContext ctx)
 {
     //if (this.Logger.IsEnabled(this.InternalLevel))
     {
         //this.Logger.Log(this.InternalLevel, this.Format(ctx, "READ"));
     }
     ctx.Read();
 }
예제 #10
0
 public override void ChannelActive(IChannelHandlerContext ctx)
 {
     _channel = ctx.Channel;
     if (!_autoRead)
     {
         ctx.Read();
     }
 }
 public override void ChannelRead(IChannelHandlerContext context, object message)
 {
     if (Volatile.Read(ref this.available) > 0)
     {
         context.Read();
     }
     base.ChannelRead(context, message);
 }
예제 #12
0
 public override void Read(IChannelHandlerContext ctx)
 {
     if (Logger.IsEnabled(InternalLevel))
     {
         Logger.Log(InternalLevel, Format(ctx, "READ"));
     }
     ctx.Read();
 }
 public override void ChannelReadComplete(IChannelHandlerContext ctx)
 {
     if (!_autoRead)
     {
         ctx.Read();
     }
     base.ChannelReadComplete(ctx);
 }
 public override void ChannelReadComplete(IChannelHandlerContext context)
 {
     base.ChannelReadComplete(context);
     if (this.InboundBacklogSize < this.mqttTransportSettings.MaxPendingInboundMessages)
     {
         context.Read();
     }
 }
예제 #15
0
 public override void ChannelRead(IChannelHandlerContext ctx, object msg)
 {
     ReferenceCountUtil.Release(msg);
     if (_count.Increment() == 1)
     {
         // Call read the first time, to ensure it is not reset the second time.
         ctx.Read(); // Socket BeginRead 没有做重复调用检测
     }
 }
 protected override void ChannelRead0(IChannelHandlerContext ctx, IByteBuffer msg)
 {
     if (Interlocked.Add(ref this.bytesRead, msg.ReadableBytes) >= this.expectedBytesRead)
     {
         this.completion.TrySetResult(this.bytesRead);
     }
     // Because autoread is off, we call read to consume all data until we detect the close.
     ctx.Read();
 }
예제 #17
0
 public override void ChannelRead(IChannelHandlerContext ctx, object msg)
 {
     ReferenceCountUtil.Release(msg);
     if (Interlocked.Increment(ref this.count) == 1)
     {
         // Call read the first time, to ensure it is not reset the second time.
         ctx.Read();
     }
 }
예제 #18
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            this.stateFlags = StateFlags.NotConnected;

            this.Connect(context);

            base.ChannelActive(context);

            context.Read();
        }
예제 #19
0
 private void ReadIfNeeded(IChannelHandlerContext ctx)
 {
     // if handshake is not finished yet, we need more data
     if (!ctx.Channel.Configuration.IsAutoRead && (!_firedChannelRead || !State.HasAny(TlsHandlerState.AuthenticationCompleted)))
     {
         // No auto-read used and no message was passed through the ChannelPipeline or the handshake was not completed
         // yet, which means we need to trigger the read to ensure we will not stall
         _ = ctx.Read();
     }
 }
예제 #20
0
        public override void Read(IChannelHandlerContext context)
        {
            State oldState = this.state;

            if ((oldState & State.AuthenticationCompleted) == 0)
            {
                this.state = oldState | State.ReadRequestedBeforeAuthenticated;
            }

            context.Read();
        }
예제 #21
0
 public override void Read(IChannelHandlerContext ctx)
 {
     if (0u >= (uint)Dequeue(ctx, 1))
     {
         // It seems no messages were consumed. We need to read() some
         // messages from upstream and once one arrives it need to be
         // relayed to downstream to keep the flow going.
         ++_readRequestCount;
         _ = ctx.Read();
     }
 }
예제 #22
0
 void ResumeReadingIfNecessary(IChannelHandlerContext context)
 {
     if (this.InboundBacklogSize == this.settings.MaxPendingInboundMessages - 1) // we picked up a packet from full queue - now we have more room so order another read
     {
         if (MqttIotHubAdapterEventSource.Log.IsVerboseEnabled)
         {
             MqttIotHubAdapterEventSource.Log.Verbose("Resuming reading from channel as queue freed up.", $"deviceId: {this.identity}, channel: {context.Channel}");
         }
         context.Read();
     }
 }
예제 #23
0
        public override void Read(IChannelHandlerContext context)
        {
            var oldState = State;

            if (!oldState.HasAny(TlsHandlerState.AuthenticationCompleted))
            {
                State = oldState | TlsHandlerState.ReadRequestedBeforeAuthenticated;
            }

            _ = context.Read();
        }
 public override void Read(IChannelHandlerContext ctx)
 {
     if (this.Dequeue(ctx, 1) == 0)
     {
         // It seems no messages were consumed. We need to read() some
         // messages from upstream and once one arrives it need to be
         // relayed to downstream to keep the flow going.
         this.shouldConsume = true;
         ctx.Read();
     }
 }
예제 #25
0
 /// <inheritdoc />
 public override void ChannelReadComplete(IChannelHandlerContext context)
 {
     _numReads = 0;
     DiscardSomeReadBytes();
     if (!_firedChannelRead && !context.Channel.Configuration.IsAutoRead)
     {
         _ = context.Read();
     }
     _firedChannelRead = false;
     _ = context.FireChannelReadComplete();
 }
예제 #26
0
            public override void Read(IChannelHandlerContext ctx, object input)
            {
                var frame = input as WebSocketFrame;

                if (frame != null)
                {
                    Console.WriteLine("[* ws frame {0} '{1}' *]", frame.Type, frame.Text);
                }

                // Проброс.
                ctx.Read(input);
            }
 public override void ChannelRead(IChannelHandlerContext ctx, object msg)
 {
     ReferenceCountUtil.Release(msg);
     if (Interlocked.Increment(ref this.count) == 1)
     {
         ctx.Channel.Configuration.AutoRead = false;
     }
     if (this.callRead)
     {
         ctx.Read();
     }
 }
        public override void ChannelActive(IChannelHandlerContext context)
        {
            this.stateFlags = StateFlags.NotConnected;

            this.Connect(context);

            // TODO #223: this executes in parallel with the Connect(context).

            base.ChannelActive(context);

            context.Read();
        }
예제 #29
0
 public override void ChannelReadComplete(IChannelHandlerContext ctx)
 {
     _clientReadCompletes.Increment();
     if (_bytesRead == _totalServerBytesWritten)
     {
         _clientReadAllDataLatch.SafeSignal();
     }
     if (!_autoRead)
     {
         ctx.Read();
     }
 }
예제 #30
0
        public override void ChannelActive(IChannelHandlerContext context)
        {
            this.stateFlags = StateFlags.WaitingForConnect;
            TimeSpan?timeout = this.settings.ConnectArrivalTimeout;

            if (timeout.HasValue)
            {
                context.Channel.EventLoop.ScheduleAsync(CheckConnectTimeoutCallback, context, timeout.Value);
            }
            base.ChannelActive(context);

            context.Read();
        }
예제 #31
0
 public override void ChannelReadComplete(IChannelHandlerContext context)
 {
     this.DiscardSomeReadBytes();
     if (this.decodeWasNull)
     {
         this.decodeWasNull = false;
         if (!context.Channel.Configuration.AutoRead)
         {
             context.Read();
         }
     }
     context.FireChannelReadComplete();
 }
예제 #32
0
        public override void Read(IChannelHandlerContext context)
        {
            State oldState = this.state;
            if ((oldState & State.AuthenticationCompleted) == 0)
            {
                this.state = oldState | State.ReadRequestedBeforeAuthenticated;
            }

            context.Read();
        }
        public override void ChannelActive(IChannelHandlerContext context)
        {
            this.stateFlags = StateFlags.WaitingForConnect;
            TimeSpan? timeout = this.settings.ConnectArrivalTimeout;
            if (timeout.HasValue)
            {
                context.Channel.EventLoop.Schedule(CheckConnectTimeoutCallback, context, timeout.Value);
            }
            base.ChannelActive(context);

            context.Read();
        }
예제 #34
0
 void ResumeReadingIfNecessary(IChannelHandlerContext context)
 {
     if (this.InboundBacklogSize == this.mqttTransportSettings.MaxPendingInboundMessages - 1) // we picked up a packet from full queue - now we have more room so order another read
     {
         context.Read();
     }
 }
 void ResumeReadingIfNecessary(IChannelHandlerContext context)
 {
     if (this.InboundBacklogSize == this.settings.MaxPendingInboundMessages - 1) // we picked up a packet from full queue - now we have more room so order another read
     {
         if (MqttIotHubAdapterEventSource.Log.IsVerboseEnabled)
         {
             MqttIotHubAdapterEventSource.Log.Verbose("Resuming reading from channel as queue freed up.", string.Format("deviceId: {0}, channel: {1}", this.deviceId, context.Channel));
         }
         context.Read();
     }
 }
예제 #36
0
 public virtual void Read(IChannelHandlerContext context) => context.Read();
 public override void ChannelReadComplete(IChannelHandlerContext context)
 {
     base.ChannelReadComplete(context);
     int inboundBacklogSize = this.InboundBacklogSize;
     if (inboundBacklogSize < this.settings.MaxPendingInboundMessages)
     {
         context.Read();
     }
     else
     {
         if (MqttIotHubAdapterEventSource.Log.IsVerboseEnabled)
         {
             MqttIotHubAdapterEventSource.Log.Verbose(
                 "Not reading per full inbound message queue",
                 string.Format("deviceId: {0}, messages queued: {1}, channel: {2}", this.deviceId, inboundBacklogSize, context.Channel));
         }
     }
 }
예제 #38
0
 public override void ChannelReadComplete(IChannelHandlerContext context)
 {
     base.ChannelReadComplete(context);
     if (this.InboundBacklogSize < this.mqttTransportSettings.MaxPendingInboundMessages)
     {
         context.Read();
     }
 }