示例#1
0
        private static void OnClose(Socket s)
        {
            SocketInfo info = new SocketInfo();

            info.type = SocketCallBack.TYPE_CLOSE;
            info.s    = s;
            SocketCallBack.Instance().AddData(info);
        }
示例#2
0
        private static void OnConnect(Socket s)
        {
            SocketInfo info = new SocketInfo();

            info.type = SocketCallBack.TYPE_ONCONNECT;
            info.s    = s;
            SocketCallBack.Instance().AddData(info);
        }
示例#3
0
 public void AddData(SocketInfo info)
 {
     //有些时候调试的时候会发生死锁现象- 待release版本测试- 2015.9.18-
     //已解决- 不是这个原因...是其他bug。。。2015.10.10
     lock (mList)
     {
         mList.Add(info);
     }
 }
示例#4
0
 public void AddData(SocketInfo info)
 {
     //有些时候调试的时候会发生死锁现象- 待release版本测试- 2015.9.18-
     //已解决- 不是这个原因...是其他bug。。。2015.10.10
     lock (mList)
     {
         mList.Add(info);
     }
 }
示例#5
0
        private static void OnReceive(Socket s, byte[] data, int nSize)
        {
            SocketInfo info = new SocketInfo();

            info.type = SocketCallBack.TYPE_RECEIVE;
            info.s    = s;
            info.data = new byte[nSize];
            Buffer.BlockCopy(data, 0, info.data, 0, nSize);
            SocketCallBack.Instance().AddData(info);
        }
示例#6
0
        public void Run()
        {
            int runtime = System.Environment.TickCount;

            while (true)
            {
                if (System.Environment.TickCount - runtime > 300)
                {
                    break;                                              //超出三百毫秒下次再处理
                }
                SocketInfo info = GetInfo();
                if (info == null)
                {
                    break;
                }
                if (info.s == null)
                {
                    break;
                }
                Socket s = info.s;
                switch (info.type)
                {
                case TYPE_ONCONNECT:
                {
                    SessionManager.Instance().AddSession(s, GameServer.GetTcpServer());
                    break;
                }

                case TYPE_CLOSE:
                {
                    PlayerObject play = UserEngine.Instance().FindPlayerObjectToSocket(s);
                    SessionManager.Instance().RemoveSession(s);
                    UserEngine.Instance().RemovePlayObject(play);
                    //if (play != null)
                    // {
                    // play.GetGameSession().Dispose();
                    // play.SetGameSession(null);
                    //}

                    break;
                }

                case TYPE_RECEIVE:
                {
                    SessionManager.Instance().AddNetData(s, info.data, info.data.Length);
                    break;
                }
                }
            }
        }
示例#7
0
        public SocketInfo GetInfo()
        {
            SocketInfo info = null;

            lock (mList)
            {
                if (mList.Count > 0)
                {
                    info = mList[0];
                    mList.RemoveAt(0);
                }
            }
            return(info);
        }
示例#8
0
 private static void OnClose(Socket s)
 {
     SocketInfo info = new SocketInfo();
     info.type = SocketCallBack.TYPE_CLOSE;
     info.s = s;
     SocketCallBack.Instance().AddData(info);
 }
示例#9
0
 private static void OnReceive(Socket s, byte[] data, int nSize)
 {
     SocketInfo info = new SocketInfo();
     info.type = SocketCallBack.TYPE_RECEIVE;
     info.s = s;
     info.data = new byte[nSize];
     Buffer.BlockCopy(data, 0, info.data, 0, nSize);
     SocketCallBack.Instance().AddData(info);
 }
示例#10
0
 private static void OnConnect(Socket s)
 {
     SocketInfo info = new SocketInfo();
     info.type = SocketCallBack.TYPE_ONCONNECT;
     info.s = s;
     SocketCallBack.Instance().AddData(info);
 }