Exemple #1
0
        // 生成 NetSession 对象
        public NetSessionImpl MallocNetSession()
        {
            NetSessionImpl netSession = null;

            lock (netSessionListlock)
            {
                if (netSessionList.Count() <= 0)
                {
                    MakeNetSession(extendPoolSize);
                }

                if (netSessionList.Count() <= 0)
                {
                    return(null);
                }

                netSession = netSessionList[0];
                netSessionList.RemoveAt(0);
            }

            if (netSession != null)
            {
                netSession.SetSessionID(sessionIndex++);
            }

            return(netSession);
        }
Exemple #2
0
        // 私有方法
        #region
        private bool MakeNetSession(Int32 makeCounts)
        {
            Trace.Assert(netSessionList != null, "netSessionList is null");
            if (netSessionList == null)
            {
                return(false);
            }

            NetSessionImpl netSession = null;

            for (Int32 i = 0; i < makeCounts; ++i)
            {
                netSession = new NetSessionImpl();
                if (netSession == null)
                {
                    return(false);
                }

                if (!netSession.Init())
                {
                    netSession = null;
                    return(false);
                }

                netSessionList.Add(netSession);
            }

            return(true);
        }
Exemple #3
0
        // 释放 NetSession 对象
        public void FreeNetSession(NetSessionImpl netSession)
        {
            Trace.Assert(netSession != null, "netSession is null");
            if (netSession == null)
            {
                return;
            }

            netSession.Reset();

            lock (netSessionListlock)
            {
                netSessionList.Add(netSession);
            }
        }