// 添加网络会话 public bool AddNetEvent(NetSessionImpl netSession, ADDORDELSESSIONEVENT eventType, EVENTSESSIONPLACE eventPlace) { if (netSession == null) { return(false); } AddOrDelSessionEvent sessionEvent = new AddOrDelSessionEvent(); sessionEvent.netSession = netSession; sessionEvent.eventType = eventType; sessionEvent.eventPlace = eventPlace; addOrDelEventList.AddElement(sessionEvent); return(true); }
public void FreeEvent(AddOrDelSessionEvent addOrDelEvent) { }
// 处理添加、删除网络会话事件 #region public void HandleAddOrDelEvent(AddOrDelSessionEvent addOrDelEvent) { NetSessionImpl netSession = addOrDelEvent.netSession; if (netSession == null) { return; } switch (addOrDelEvent.eventType) { case ADDORDELSESSIONEVENT.addNetSession: { // 设置会话的状态 NetSessionState sessionState = new NetSessionState(); sessionState.Reset((Int32)NETSESSIONSTATE.netSessionStateUsing); netSession.SetSessionState(ref sessionState); if (!netSession.PostRcv()) { // 关闭会话,返回会话池 NetSessionPool.GetInstance().FreeNetSession(netSession); } else { netSessionDic.Add(netSession.GetSessionID(), netSession); // 通知上层 if (netSessionConnectedCallbackFunc != null) { netSessionConnectedCallbackFunc((INetSession)netSession, addOrDelEvent.eventPlace, true); } } } break; case ADDORDELSESSIONEVENT.delNetSession: { // 通知应用层 if (addOrDelEvent.eventPlace != EVENTSESSIONPLACE.appDelSession) { if (netSessionClosedCallbackFunc != null) { netSessionClosedCallbackFunc(addOrDelEvent.netSession, addOrDelEvent.eventPlace); } NetSessionState sessionState = new NetSessionState(); sessionState.Reset((Int32)NETSESSIONSTATE.netSessionStateMax); sessionState.appUseState = (Int32)NETSESSIONSTATE.netSessionStateShutdown; addOrDelEvent.netSession.SetSessionState(ref sessionState); } } break; case ADDORDELSESSIONEVENT.asyncConnectFailed: { // 通知上层 if (netSessionConnectedCallbackFunc != null) { netSessionConnectedCallbackFunc((INetSession)netSession, addOrDelEvent.eventPlace, false); } // 关闭会话,返回会话池 NetSessionPool.GetInstance().FreeNetSession(netSession); } break; default: break; } }