Beispiel #1
0
        /// <summary>
        /// 帧更新
        /// </summary>
        public void Update()
        {
            while (m_ListenedEvent.IsEmpty() == false)
            {
                System.Object objInfo = null;
                if (m_ListenedEvent.Pop(ref objInfo) == false || objInfo == null)
                {
                    continue;
                }
                CEventInfo info = objInfo as CEventInfo;
                if (info == null)
                {
                    continue;
                }
                UInt32        uEventId = info.GetEventId();
                System.Object objParam = info.GetEventParam();

                m_EventInfoPool.GiveBackObject(info);

                CHandleInfo handleInfo = null;
                if (m_EventActionList.QuickFind(uEventId, ref handleInfo) == false || handleInfo == null)
                {
                    continue;
                }
                bool bTriggerRet = handleInfo.TriggerHandle(objParam);
                if (bTriggerRet == false)
                {
                    BTDebug.Warning(string.Format("Trigger Event:{0} With Param:{2} Failed", uEventId, objParam), "ACTION");
                }
            }
        }
Beispiel #2
0
 // 更新
 public void OnUpdateConnect()
 {
     while (m_QueMsgReceive.IsEmpty() == false)
     {
         System.Object refObj = null;
         if (m_QueMsgReceive.Pop(ref refObj) == false)
         {
             break;
         }
         if (refObj == null)
         {
             continue;
         }
         Byte[] receByteArray = refObj as Byte[];
         if (receByteArray == null)
         {
             BTDebug.Warning("Receive Data Not Packed as Byte Array", "NET");
             continue;
         }
         if (m_HandleOnReceiveMsg != null)
         {
             m_HandleOnReceiveMsg(receByteArray);
         }
     }
 }
Beispiel #3
0
        //#####################################################################################

        public NetMessage ReceiveMessage()
        {
            return(m_messageQueue.Pop());
        }
Beispiel #4
0
        //#####################################################################################
        // 쓰레드 작업 함수

        protected void SenderThreadJob()
        {
            try
            {
                while (m_senderRun)
                {
                    Thread.Sleep(2);


                    // 메세지가 있고 실행 플래그가 서있으면
                    while (!m_messageQueue.IsEmpty && m_senderRun)
                    {
                        // 하나 뽑아내서
                        var messageToSend = m_messageQueue.Pop();

                        // 있으면
                        if (messageToSend != null)
                        {
                            int currentSeq = m_sequenceNumber;

                            // 처음 보내는 메세지가 아니면 시퀀스를 이전 메세지의 시퀀스로 설정
                            if (messageToSend.RetryCount > 0)
                            {
                                currentSeq = messageToSend.Header.SequenceNumber;
                            }

                            // 시퀀스 번호 설정하고
                            messageToSend.Header.SequenceNumber = currentSeq;

                            // 암호화된 데이터 얻음
                            var bytesToSend = messageToSend.GetEncryptedBytes(m_key);

                            if (bytesToSend != null)
                            {
                                // 백업 여유공간 확보
                                m_backupMsgList.DoSync((list) =>
                                {
                                    while (currentSeq >= list.Count)
                                    {
                                        list.Add(new KeyValuePair <NetMessage, DateTime>(null, DateTime.MinValue));
                                    }
                                });


                                // 정상수신 응답 메세지가 아니면
                                if (messageToSend.Header.MessageNumber != (int)NetProtocols.CheckPacket)
                                {
                                    // 백업
                                    m_backupMsgList.DoSync((list) =>
                                    {
                                        list[currentSeq] = new KeyValuePair <NetMessage, DateTime>(messageToSend,
                                                                                                   DateTime.Now);
                                    });
                                }


                                // 메세지 전송
                                try
                                {
                                    int beginSend = 0;

                                    while (beginSend < bytesToSend.Length)
                                    {
                                        int sendSize = m_socket.Send(bytesToSend, beginSend,
                                                                     bytesToSend.Length - beginSend, SocketFlags.None);
                                        beginSend += sendSize;
                                    }
                                }
                                catch
                                {
                                    m_senderRun = false;
                                    break;
                                }


                                // 처음 보내는 메세지이면
                                if (messageToSend.RetryCount <= 0)
                                {
                                    // 시퀀스 번호 상승
                                    ++m_sequenceNumber;

                                    if (m_sequenceNumber > this.MaxBackupSequence)
                                    {
                                        m_sequenceNumber = 0;
                                    }
                                }
                            }
                        }


                        Thread.Sleep(TimeSpan.Zero);
                    }
                }
            }
            catch (IOException)
            {
                m_senderRun = false;
            }
            catch (ThreadAbortException)
            {
                m_senderRun = false;
            }
            catch (ObjectDisposedException)
            {
                m_senderRun = false;
            }
#if !DEBUG
            catch
            {
                m_senderRun = false;
            }
#endif
        }