Beispiel #1
0
    void ProcessRecvBuffer(Message message)
    {
        Log.InfoFormat("[ProcessRecvBuffer] receive message seq = {0} ack = {1} ctrl = {2}", message.seq, message.ack, message.ctrl);
        if (message.ctrl == (byte)ESAFlag.Ctrl)// ctrl message
        {
            Log.InfoFormat("[Info] ProcessRecvBuffer Receive Ctrl Message");
            //  receive syn & ack message
            if (message.syn == 1)
            {
                if (_eConnectState == EConnectState.SYN_SENT)
                {
                    _base   = (byte)(message.ack + 1);
                    _svrSeq = message.seq;
                    OnReceiveAck();
                    SendCtrlAck();
                    _eConnectState = EConnectState.ESTABLISHED;
                    Log.InfoFormat("ProcessRecvBuffer _eConnectState from {0} to {1}", EConnectState.SYN_SENT, _eConnectState);
                }
                else
                {
                    Log.InfoFormat("[Info] Receive syn with _eConnectState = {0}", _eConnectState);
                }
            }
            else if (message.fin == 1)
            {
                if (_eConnectState == EConnectState.FIN_WAIT_2)
                {
                    SendCtrlAck();
                    _eConnectState = EConnectState.TIME_WAIT;
                    Log.InfoFormat("[Info] Receive Fin, Send Ack, _eConnectState from {0} to {1}", EConnectState.FIN_WAIT_2, _eConnectState);
                    _finCountdownId = CountdownTimer.Instance.StartTimer(3, FinCountdown);
                }
                else
                {
                    Log.InfoFormat("[Info] Receive Fin while _eConnectState = {0}", _eConnectState);
                }
            }
            else if (_eConnectState == EConnectState.FIN_WAIT_1)// receive ack message for fin
            {
                _base = (byte)(message.ack + 1);
                OnReceiveAck();
                _eConnectState = EConnectState.FIN_WAIT_2;
                Log.InfoFormat("[Info] Receive Ack Send Nothing, _eConnectState = {0}", _eConnectState);
            }
        }
        else if (message.ctrl == (byte)ESAFlag.Seq) // seq
        {
            Log.InfoFormat("[Info] ProcessRecvBuffer Receive seq message");
            if (message.seq != GetSvrSeq())
            {
                // ignore receiver 's message
                Log.InfoFormat("[Info] Receive message.seq = {0} != _svrSeq {1}, discard", message.seq, _svrSeq);
                ResendAck();
                return;
            }
            // receive message correctly
            // handle message
            // set server seq
            _svrSeq = message.seq;
            Log.InfoFormat("[Info] ProcessRecvBuffer message.seq = {0}", message.seq);

            SendAck();
            _networkclient.PostMessage(message);
        }
        else if (message.ctrl == (byte)ESAFlag.Ack) //ack
        {
            var ack = message.ack;
            _base = (byte)(ack);

            Log.InfoFormat("[Info] ProcessRecvBuffer Receive ack message ack = {0}", ack);
            OnReceiveAck();
        }
    }