Example #1
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();
            }
        }