示例#1
0
        private void _ProcRecvEvent(LPNetEvent netEvent)
        {
            bool           result    = false;
            LPRecvNetEvent recvEvent = null;

            if (LOG_ERROR(netEvent != null))
            {
                goto Exit0;
            }

            recvEvent = (LPRecvNetEvent)netEvent;
            if (LOG_ERROR(recvEvent.RecvLength < LP.MaxPacketLen))
            {
                goto Exit0;
            }

            result = m_EventBuf.Read(m_TempPacketBuf, 0, recvEvent.RecvLength, true);
            if (LOG_ERROR(result))
            {
                goto Exit0;
            }

            m_NetMessageHandler.OnMessage(recvEvent.Socker, m_TempPacketBuf, recvEvent.RecvLength);

Exit0:
            return;
        }
示例#2
0
        public int Parse(LPLoopBuf loopBuf)
        {
            bool   result      = false;
            int    parseCount  = -1;
            UInt16 MsgId       = 0;
            UInt16 MsgSize     = 0;
            int    MsgHeadSize = 4;

            byte[] MsgIdBytes = new byte[MsgHeadSize];

            if (LOG_ERROR(loopBuf != null))
            {
                goto Exit0;
            }

            if (loopBuf.GetTotalReadableLen() >= MsgHeadSize)
            {
                if (LOG_ERROR(MsgIdBytes != null))
                {
                    goto Exit0;
                }
                result = loopBuf.Read(MsgIdBytes, 0, MsgHeadSize, false);
                if (LOG_ERROR(result))
                {
                    goto Exit0;
                }

                MsgId = (UInt16)(MsgIdBytes[0] | MsgIdBytes[1]);
                if (LOG_ERROR(MsgId > LPProtocol.min_message_id && MsgId < LPProtocol.max_message_id))
                {
                    goto Exit0;
                }

                MsgSize = (UInt16)(MsgIdBytes[2] | MsgIdBytes[3]);
                if (loopBuf.GetTotalReadableLen() >= MsgSize)
                {
                    parseCount = MsgSize;
                    if (SUCCESS(true))
                    {
                        goto Exit1;
                    }
                }
            }

            parseCount = 0;
            if (SUCCESS(true))
            {
                goto Exit1;
            }

Exit0:
            parseCount = -1;

Exit1:
            return(parseCount);
        }
示例#3
0
        private static void _ThreadProc(Object param)
        {
            bool bResult                 = false;
            int  nSleepMicSec            = 10;       // 每次睡眠毫秒数
            int  nFlushIntervalSec       = 3000;     // flush间隔(毫秒)
            int  nLastFlushTimeMicSecInc = 0;        // 上次flush后的时间增量(毫秒)
            int  nStopRunWaitCount       = 0;

            int          nOnceReadableLen = 0;
            LPFileLogger oFileLogger      = null;
            LPLoopBuf    oLoopBuf         = null;

            int nLen = 0;

            byte[] lenBytes = null;

            oFileLogger = (LPFileLogger)param;
            if (PTF_ERROR(oFileLogger != null))
            {
                goto Exit0;
            }
            oLoopBuf = oFileLogger.m_oLoopBuf;
            if (PTF_ERROR(oLoopBuf != null))
            {
                goto Exit0;
            }

            lenBytes = new byte[sizeof(int)];
            if (PTF_ERROR(lenBytes != null))
            {
                goto Exit0;
            }

            while (oFileLogger.m_bRun || oLoopBuf.GetOnceReadableLen() > 0)
            {
                //防止LPLoopBuf出错造成不退出(等待500 * 10毫米)
                if (!oFileLogger.m_bRun)
                {
                    ++nStopRunWaitCount;
                    if (nStopRunWaitCount > 500)
                    {
                        PTF_ERROR(false);
                        break;
                    }
                }

                while (oLoopBuf.GetTotalReadableLen() > sizeof(int))
                {
                    bResult = oLoopBuf.Read(lenBytes, 0, sizeof(int), false);
                    PTF_ERROR(bResult);

                    nLen = BitConverter.ToInt32(lenBytes, 0);
                    if (oLoopBuf.GetTotalReadableLen() < nLen)
                    {
                        break;
                    }

                    oLoopBuf.FinishRead(sizeof(int));
                    oFileLogger._UpdateFilePointer();

                    nOnceReadableLen = oLoopBuf.GetOnceReadableLen();

                    if ((oFileLogger.m_nOutputMask & (int)EOutputType.File) > 0)
                    {
                        if (nOnceReadableLen < nLen)
                        {
                            oFileLogger.m_oFile.Write(oLoopBuf.BufBytes,
                                                      oLoopBuf.ReadInx, nOnceReadableLen);
                            oFileLogger.m_oFile.Write(oLoopBuf.BufBytes,
                                                      0, nLen - nOnceReadableLen);
                        }
                        else
                        {
                            oFileLogger.m_oFile.Write(oLoopBuf.BufBytes,
                                                      oLoopBuf.ReadInx, nLen);
                        }
                    }

                    oLoopBuf.FinishRead(nLen);

                    oFileLogger.m_bDirty = true;
                }

                if (oFileLogger.m_bErrorLog)
                {
                    oLoopBuf.FinishRead(oLoopBuf.GetTotalReadableLen());
                    oFileLogger.m_bErrorLog = false;
                }

                nLastFlushTimeMicSecInc += nSleepMicSec;
                if (nLastFlushTimeMicSecInc > nFlushIntervalSec)
                {
                    nLastFlushTimeMicSecInc = 0;
                    oFileLogger._Flush();
                }

                if (oLoopBuf.GetTotalReadableLen() <= sizeof(int))
                {
                    Thread.Sleep(nSleepMicSec);
                }
            }

Exit0:

            oFileLogger._Flush();

            return;
        }