public void Release()
        {
            ValidReleaseOnce();

            GatewayServer gateway_s = null;

            while (m_FreeGatewayQueue.Count > 0)
            {
                gateway_s = m_FreeGatewayQueue.Dequeue();
                gateway_s.Release();
                gateway_s = null;
            }

            m_FreeGatewayQueue = null;

            foreach (GatewayServer tmp_gateway_s in m_ConnectedGatewayList)
            {
                tmp_gateway_s.Release();
            }

            m_ConnectedGatewayList.Clear();
            m_ConnectedGatewayList = null;

            foreach (GatewayServer tmp_gateway_s in m_AuthedGatewayDict.Values)
            {
                tmp_gateway_s.Release();
            }

            m_AuthedGatewayDict.Clear();
            m_AuthedGatewayDict = null;
        }
Beispiel #2
0
        protected override SOCK_SERV_ERROR AddToRelevantManager(Session sess)
        {
            SOCK_SERV_ERROR ret = SOCK_SERV_ERROR.SUCCESS;

            Debug.Assert(null != sess);
            Debug.Assert(sess is TcpSession);

            GatewayServer server = GatewayServerManager.Instance.AllocateGatewayServer();

            if (null != server)
            {
                TcpSession server_sess = (TcpSession)sess;
                server_sess.SetObject(server);

                server.SetServerSession(server_sess);

                GatewayServerManager.Instance.AddConnectedGatewayServer(server);
            }
            else
            {
                ret = SOCK_SERV_ERROR.E_SERVER_SESSION_IS_EMPTY;
            }

            return(ret);
        }
        private void FreeGatewayServer(GatewayServer gateway_s)
        {
            if (null == gateway_s)
            {
                return;
            }

            m_FreeGatewayQueue.Enqueue(gateway_s);
        }
        public void AddConnectedGatewayServer(GatewayServer gateway_s)
        {
            Debug.Assert(!m_ConnectedGatewayList.Contains(gateway_s));

            m_ConnectedGatewayList.TryAdd(gateway_s);

            LogManager.Debug("Add connected gateway server. Gateway server ID = " +
                             gateway_s.GatewayServerID.ToString());
        }
        private void DynamicAllocateGatewayServer(int gateway_server_num)
        {
            GatewayServer gateway_s = null;

            for (int i = 0; i < gateway_server_num; ++i)
            {
                gateway_s = new GatewayServer();
                m_FreeGatewayQueue.Enqueue(gateway_s);
                gateway_s = null;
            }
        }
        public void RemoveGatewayServer(GatewayServer gateway_s)
        {
            m_AuthedGatewayDict.TryRemove(gateway_s.GatewayServerID, out GatewayServer tmp_gate_s);

            m_ConnectedGatewayList.TryRemove(gateway_s);

            LogManager.Debug("Remove connected gateway server. Gateway server ID " +
                             gateway_s.GatewayServerID.ToString());

            FreeGatewayServer(gateway_s);
        }
        public GatewayServer AllocateGatewayServer()
        {
            if (0 == m_FreeGatewayQueue.Count)
            {
                DynamicAllocateGatewayServer(DYNAMIC_GATEWAY_SERVER_NUM);
            }

            GatewayServer gateway_s = m_FreeGatewayQueue.Dequeue();

            Debug.Assert(null != gateway_s);
            return(gateway_s);
        }
        public static int PacketProcessAuth(object obj, Packet pkt)
        {
            Debug.Assert(null != obj);
            Debug.Assert(obj is GatewayServer);
            Debug.Assert(Protocol.GW_ACT_AUTH == pkt.GetPacketID());

            GatewayServer gateway_server = obj as GatewayServer;

            uint gateway_server_id = pkt.GetUint();

            LogManager.Info("Receive gateway server auth pakcet: Gateway server ID = " +
                            gateway_server_id.ToString());

            gateway_server.SetServerID(gateway_server_id);
            GatewayServerManager.Instance.AddAuthedGatewayServer(gateway_server);

            gateway_server.SendAuthPacket(gateway_server_id);

            return((int)PacketProcessManager.PACKET_PROC_ERROR.SUCCESS);
        }
        public void AddAuthedGatewayServer(GatewayServer gateway_s)
        {
            Debug.Assert(m_ConnectedGatewayList.IndexOf(gateway_s) > -1);

            if (m_ConnectedGatewayList.TryRemove(gateway_s))
            {
            }
            else
            {
                Debug.Assert(false);
            }

            if (m_AuthedGatewayDict.TryRemove(gateway_s.GatewayServerID, out GatewayServer tmp_gateway_s))
            {
                Debug.Assert(false);
                FreeGatewayServer(tmp_gateway_s);
            }

            m_AuthedGatewayDict.TryAdd(gateway_s.GatewayServerID, gateway_s);

            LogManager.Debug("Add authed gateway server. Gateway server ID = " +
                             gateway_s.GatewayServerID.ToString());
        }