public LPListener CreateListener(IPAddress addr, int nPort, ILPPacketParser packetParser) { LPListener listener = null; TcpListener tl = null; if (LOG_ERROR(packetParser != null)) { goto Exit0; } listener = new LPListener(); if (LOG_ERROR(listener != null)) { goto Exit0; } tl = new TcpListener(addr, nPort); if (LOG_ERROR(tl != null)) { goto Exit0; } listener.Listener = tl; listener.ID = _GenerateListenerID(); listener.PacketParser = packetParser; return(listener); Exit0: return(null); }
public void OnAccept(IAsyncResult ar) { bool result = false; LPSocker socker = null; Socket socket = null; LPListener listener = null; HandlerParam handlerParam = null; IAsyncResult retAr = null; try { if (LOG_ERROR(ar != null)) { goto Exit0; } handlerParam = (HandlerParam)ar.AsyncState; if (LOG_ERROR(handlerParam != null)) { goto Exit0; } if (LOG_ERROR(handlerParam.HandlerType == EHandlerType.Listener)) { goto Exit0; } listener = (LPListener)handlerParam.Handler; LP.Logger.IMP("accept success."); socket = listener.Listener.EndAcceptSocket(ar); if (LOG_ERROR(socket != null)) { goto Exit0; } retAr = listener.Listener.BeginAcceptSocket(LP.NetModule.Reactor.OnAccept, handlerParam); if (LOG_ERROR(retAr != null)) { goto Exit0; } socker = LP.NetModule.CreateSocker(socket, listener.PacketParser, listener, true); if (LOG_ERROR(socker != null)) { goto Exit0; } result = LP.NetModule.EventMgr.PushEstablishEvent(socker); if (LOG_ERROR(result)) { goto Exit0; } } catch (SocketException e) { //if(!listener.IsStoped) { LP.Logger.P_ERR("ErrorCode={0},SocketErrorCode={1}, Message:{2}, StackTrace:{3}", e.ErrorCode, e.SocketErrorCode, e.Message, e.StackTrace); } } catch (Exception e) { LPMiniDump.GenerateNormalDump(e); } Exit0: return; }