예제 #1
0
 public void AddConnection(AleTunnel item)
 {
     lock (_tunnels.SyncRoot)
     {
         if (!_tunnels.Contains(item))
         {
             _tunnels.Add(item);
         }
     }
 }
예제 #2
0
        void IAleTunnelObserver.OnAleFrameArrival(AleTunnel theConnection, AleFrame theFrame)
        {
            try
            {
                lock (_stateInputEventSyncLock)
                {
                    if (CheckFrame(theFrame))
                    {
                        // D类服务时,序列号有效;A类服务时,序列号无效。
                        if (_rsspEndPoint.ServiceType == ServiceType.D &&
                            theFrame.FrameType == AleFrameType.DataTransmission)
                        {
                            _seqNoManager.UpdateAckSeq(theFrame.SequenceNo);
                        }

                        //
                        if (theFrame.FrameType == AleFrameType.ConnectionRequest)
                        {
                            LogUtility.Info(string.Format("{0}: Received a CR frame on tcp connection(LEP={1}, REP={2}).",
                                                          this.RsspEP.ID, theConnection.LocalEndPoint, theConnection.RemoteEndPoint));

                            theConnection.Observer = this;

                            _currentState.HandleConnectionRequestFrame(theConnection, theFrame);
                        }
                        else if (theFrame.FrameType == AleFrameType.ConnectionConfirm)
                        {
                            LogUtility.Info(string.Format("{0}: Received a CC frame on tcp connection(LEP={1}, REP={2})).",
                                                          this.RsspEP.ID, theConnection.LocalEndPoint, theConnection.RemoteEndPoint));

                            _currentState.HandleConnectionConfirmFrame(theConnection, theFrame);
                        }
                        else if (theFrame.FrameType == AleFrameType.Disconnect)
                        {
                            _currentState.HandleDiFrame(theConnection, theFrame);
                        }
                        else if (theFrame.FrameType == AleFrameType.DataTransmission)
                        {
                            _currentState.HandleDataTransmissionFrame(theConnection, theFrame);
                        }
                    }
                    else if (_seqNoManager.IsBeyondRange(theFrame.SequenceNo))
                    {
                        throw new Exception(string.Format("检测到丢包,当前确认序号={0},收到的发送序号={1},TCP ID = {2}",
                                                          _seqNoManager.AckSeq, theFrame.SequenceNo, theConnection.ID));
                    }
                }
            }
            catch (System.Exception ex)
            {
                LogUtility.Error(string.Format("ALE: {0} : {1}", _rsspEndPoint.ID, ex));
                theConnection.Disconnect();
            }
        }
예제 #3
0
        public void RemoveCloseConnection(AleTunnel theConnection)
        {
            if (theConnection.IsHandShaken)
            {
                this.DescreaseValidConnection();
                theConnection.IsHandShaken = false;
            }

            _tunnels.Remove(theConnection);
            theConnection.Close();
        }
예제 #4
0
 protected override void HandleTunnelDisconnected(AleTunnel theConnection, string reason)
 {
     try
     {
         // 服务器端,移除并关闭此连接。
         this.RemoveCloseConnection(theConnection);
     }
     catch (System.Exception ex)
     {
         LogUtility.Error(ex.ToString());
     }
 }
예제 #5
0
 protected override void HandleTunnelDisconnected(AleTunnel theConnection, string reason)
 {
     try
     {
         // 客户端:减少有效的连接个数。
         if (theConnection.IsHandShaken)
         {
             this.DescreaseValidConnection();
             theConnection.IsHandShaken = false;
         }
     }
     catch (System.Exception ex)
     {
         LogUtility.Error(ex.ToString());
     }
 }
예제 #6
0
        void IAleTunnelObserver.OnTcpDisconnected(AleTunnel theConnection, string reason)
        {
            try
            {
                LogUtility.Info(string.Format("{0}: A TCP Connection disconnected. LEP = {1}, REP = {2}",
                                              this.RsspEP.ID, theConnection.LocalEndPoint, theConnection.RemoteEndPoint));

                this.HandleTunnelDisconnected(theConnection, reason);

                // 通知观察器连接关闭。
                var args = new TcpDisconnectedEventArgs(theConnection.ID,
                                                        _rsspEndPoint.LocalID, theConnection.LocalEndPoint,
                                                        _rsspEndPoint.RemoteID, theConnection.RemoteEndPoint);
                _tunnelEventNotifier.NotifyTcpDisconnected(args);
            }
            catch (System.Exception ex)
            {
                LogUtility.Error(ex.ToString());
            }
        }
예제 #7
0
 protected abstract void HandleTunnelDisconnected(AleTunnel theConnection, string reason);
예제 #8
0
 public bool ContainsTunnel(AleTunnel tunnel)
 {
     return(_tunnels.Contains(tunnel));
 }