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; }
private LPNetEvent _CreateEvent(ENetEventType eType) { LPNetEvent netEvent = null; switch (eType) { case ENetEventType.Recv: { netEvent = new LPRecvNetEvent(); if (LOG_ERROR(netEvent != null)) { goto Exit0; } netEvent.eType = ENetEventType.Recv; } break; case ENetEventType.Terminate: { netEvent = new LPTerminateNetEvent(); if (LOG_ERROR(netEvent != null)) { goto Exit0; } netEvent.eType = ENetEventType.Terminate; } break; case ENetEventType.Establish: { netEvent = new LPEstablishNetEvent(); if (LOG_ERROR(netEvent != null)) { goto Exit0; } netEvent.eType = ENetEventType.Establish; } break; case ENetEventType.ConnectError: { netEvent = new LPConnectErrorNetEvent(); if (LOG_ERROR(netEvent != null)) { goto Exit0; } netEvent.eType = ENetEventType.ConnectError; } break; default: if (LOG_ERROR(false)) { goto Exit0; } break; } return(netEvent); Exit0: return(null); }
internal bool PushRecvEvent(LPSocker socker, LPLoopBuf recvLoopBuf, int len) { bool result = false; int retryCount = 0; int lineSize = 0; LPRecvNetEvent recvEvent = null; if (LOG_ERROR(socker != null)) { goto Exit0; } if (LOG_ERROR(recvLoopBuf != null)) { goto Exit0; } recvEvent = (LPRecvNetEvent)_CreateEvent(ENetEventType.Recv); if (LOG_ERROR(recvEvent != null)) { goto Exit0; } while (m_EventBuf.GetTotalWritableLen() < len) { LP.Logger.P_WRN("event buf not enough, sleep and try again !"); Thread.Sleep(1); ++retryCount; // 超过10秒,丢弃 if (retryCount > 10000) { recvLoopBuf.FinishRead(len); if (LOG_ERROR(false)) { goto Exit0; } } } lineSize = recvLoopBuf.GetOnceReadableLen(); if (lineSize > len) { lineSize = len; } result = m_EventBuf.Write(recvLoopBuf.BufBytes, recvLoopBuf.ReadInx, lineSize); LOG_ERROR(result); recvLoopBuf.FinishRead(lineSize); if (lineSize < len) { result = m_EventBuf.Write(recvLoopBuf.BufBytes, recvLoopBuf.ReadInx, len - lineSize); LOG_ERROR(result); recvLoopBuf.FinishRead(len - lineSize); } recvEvent.Flag = socker.ID; recvEvent.RecvLength = len; recvEvent.Socker = socker; lock (m_EventListLocker[recvEvent.Flag % m_EventListCount]) { result = m_EventLists[recvEvent.Flag % m_EventListCount].PushRear(recvEvent); if (LOG_ERROR(result)) { goto Exit0; } } return(true); Exit0: return(false); }