示例#1
0
 // 关闭对象
 public void Shutdown()
 {
     CloseAllSession();
     NetSessionPool.GetInstance().Release();
     DataBufferPool.GetInstance().Release();
     MsgBufferMgr.GetInstance().Release();
     MsgBufferPool.GetInstance().Release();
     if (netSessionIDList != null)
     {
         netSessionIDList.Clear();
         netSessionIDList = null;
     }
     if (addOrDelEventList != null)
     {
         addOrDelEventList.ReleaseWriteReadList();
         addOrDelEventList = null;
     }
 }
示例#2
0
        // 初始化对象
        public bool Init(ref NetModuleInit netModuleInit, HandleNetMessage netMsgHandle)
        {
            if (netMsgHandle == null)
            {
                Trace.Assert(false, "netMsgHandle is null");
                return(false);
            }

            Trace.Assert(netModuleInit.netSessionClosedCallbackFunc != null, "netModuleInit.netSessionClosedCallbackFunc is null");
            Trace.Assert(netModuleInit.netSessionConnectedCallbackFunc != null, "netModuleInit.netSessionConnectedCallbackFunc is null");
            if (netModuleInit.netSessionClosedCallbackFunc == null || netModuleInit.netSessionConnectedCallbackFunc == null)
            {
                return(false);
            }

            netSessionClosedCallbackFunc    = netModuleInit.netSessionClosedCallbackFunc;
            netSessionConnectedCallbackFunc = netModuleInit.netSessionConnectedCallbackFunc;

            netSessionIDList = new List <int>();
            if (netSessionIDList == null)
            {
                return(false);
            }

            netSessionDic = new Dictionary <int, NetSessionImpl>();
            if (netSessionDic == null)
            {
                Trace.Assert(false, "netSessionDic is null");
                return(false);
            }

            addOrDelEventList = new WriteReadList <AddOrDelSessionEvent>();
            if (addOrDelEventList == null ||
                !addOrDelEventList.InitWriteReadList(HandleAddOrDelEvent, FreeEvent))
            {
                Trace.Assert(false, "addOrDelEventList is error");
                return(false);
            }

            // 初始化网络消息池
            if (!MsgBufferPool.GetInstance().Init(netModuleInit.msgBufferCounts,
                                                  netModuleInit.msgBufferSize))
            {
                Trace.Assert(false, "MsgBufferPool init false");
                return(false);
            }

            // 初始化消息管理器
            if (!MsgBufferMgr.GetInstance().Init(netMsgHandle))
            {
                Trace.Assert(false, "MsgBufferMgr init false");
                return(false);
            }

            // 初始化数据缓冲区
            if (!DataBufferPool.GetInstance().Init(netModuleInit.bufferReserves,
                                                   netModuleInit.sendBufSize,
                                                   netModuleInit.sendBufExtend,
                                                   netModuleInit.rcvBufSize,
                                                   netModuleInit.rcvBufExtend))
            {
                Trace.Assert(false, "DataBufferPool init false");
                return(false);
            }

            // 初始化网络会话池
            if (!NetSessionPool.GetInstance().Init(netModuleInit.sessionInitCount,
                                                   netModuleInit.sessionExtendCount))
            {
                Trace.Assert(false, "NetSessionPool init false");
                return(false);
            }

            return(true);
        }