Esempio n. 1
0
 private void ChannelOnDisconnected(IChannel channel, ShutdownReason reason)
 {
     ChangeTimerState(false);
     _sentBatch = false;
     FailedQueuedLetters();
     ChannelDisconnected?.Invoke(this, reason);
 }
Esempio n. 2
0
        private void LockedShutdown(ShutdownReason reason)
        {
            if (!_remoteShutdownRequested)
            {
                ChannelDisconnecting?.Invoke(this, reason);
            }

            if (reason == ShutdownReason.Requested)
            {
                var letter = new Letter.Letter(LetterOptions.Ack)
                {
                    Type = LetterType.Shutdown
                };
                InternalEnqueue(letter);

                if (_options.ShutdownGrace.TotalMilliseconds > 0)
                {
                    Thread.Sleep((int)_options.ShutdownGrace.TotalMilliseconds);
                }
                else
                {
                    Thread.Sleep(10);
                }
            }

            bool wasConnected = IsConnected;

            _initalizationCount = 0;
            IsConnected         = false;

            _transmitter?.Stop();
            _receiver?.Stop();

            DisconnectSocket();
            WaitForTranseiviersToShutDown();

            FailQueuedLetters();
            FailedReceivedLetters();

            if (wasConnected)
            {
                ChannelDisconnected?.Invoke(this, _remoteShutdownRequested ? ShutdownReason.Remote : reason);
            }
        }
 private void RaiseChannelDisconnectedEvent()
 {
     if (ChannelDisconnected != null)
     {
         try
         {
             foreach (EventHandler <ChannelDisconnectedEventArgs> function in ChannelDisconnected.GetInvocationList())
             {
                 try
                 {
                     function.BeginInvoke(this, new ChannelDisconnectedEventArgs(_contract, "The service has unexpectedly disconnected."), OnNotifyChannelDisconnectedEventCompleted, function);
                 }
                 catch (Exception ex)
                 {
                     ExceptionHandler.Handle(ex);
                 }
             }
         }
         catch (Exception ex)
         {
             ExceptionHandler.Handle(ex);
         }
     }
 }
Esempio n. 4
0
        protected void OnNewChannelConnected(Stream stream, string channelName, CancellationToken token)
        {
            var channel = new QpServerChannel(this, stream, channelName, token, options.Clone());

            //将通道加入到全部通道列表里面
            lock (channelList)
            {
                channelList.Add(channel);
                Channels = channelList.ToArray();
            }

            //认证通过后,才将通道添加到已认证通道列表里面
            channel.Auchenticated += (sender, e) =>
            {
                lock (auchenticatedChannelList)
                {
                    auchenticatedChannelList.Add(channel);
                    AuchenticatedChannels = auchenticatedChannelList.ToArray();
                }
            };
            channel.Disconnected += (sender, e) =>
            {
                if (LogUtils.LogConnection)
                {
                    LogUtils.Log("[Connection]{0} Disconnected.", channelName);
                }
                RemoveChannel(channel);
                try { stream.Dispose(); }
                catch { }
                ChannelDisconnected?.Invoke(this, channel);
            };
            Task.Run(() =>
            {
                ChannelConnected?.Invoke(this, channel);
            });
        }