예제 #1
0
        // 初始化
        public NetSocket(ServerTask _serverTaskCtx = null)
        {
            serverTask      = _serverTaskCtx;
            unPackCache.buf = null;
            unPackCache.len = 0;

            if (serverTask == null)
            {
                return;
            }

            Server server = serverTask.GetServer();

            SetDePacketor(server.dePacketor);

            unPackHeadLen = dePacketor.GetPackHeadPreLength();

            UniqueID uniqueID = UniqueID.GetInstance();

            if (server.serverTaskCount > 1)
            {
                id = uniqueID.gen_multi();
            }
            else
            {
                id = uniqueID.gen();
            }
        }
예제 #2
0
        void OnSendCallBack(IAsyncResult ar)
        {
            Packet packet = ar.AsyncState as Packet;

            packet.ar = ar;
            ServerTask serverTask = packet.serverTask;

            serverTask.PostSendedTask(packet);
        }
예제 #3
0
        void OnReceiveCallBack(IAsyncResult ar)
        {
            Packet packet = ar.AsyncState as Packet;

            packet.ar = ar;
            ServerTask serverTask = packet.serverTask;

            serverTask.PostRecvedTask(packet);
        }
예제 #4
0
        void OnConnectCallBack(IAsyncResult ar)
        {
            Packet packet = ar.AsyncState as Packet;

            packet.ar = ar;
            ServerTask serverTask = packet.serverTask;

            serverTask.PostConnectedServerTask(packet);
        }
예제 #5
0
        public Timer CreateTimer(int serverTaskIdx, Timer.TimerCallBack timerCB, object param, int durationMS)
        {
            if (isStop)
            {
                return(null);
            }

            ServerTask    serverTask    = serverTaskMgr.GetServerTask(serverTaskIdx);
            TaskProcesser taskProcesser = serverTask.GetMainTaskProcesser();
            Timer         timer         = new Timer(taskProcesser, durationMS, timerCB, param);

            return(timer);
        }
예제 #6
0
        public ServerTaskMgr(Server _serverCtx)
        {
            server          = _serverCtx;
            serverTaskCount = server.serverTaskCount;

            serverTaskList      = new ServerTask[serverTaskCount];
            serverTaskStateList = new ServerTaskState[serverTaskCount];

            for (int i = 0; i < serverTaskCount; i++)
            {
                serverTaskList[i] = new ServerTask(this);
            }

            //
            taskProcesser = new CommonTaskProcesser();
        }
예제 #7
0
        public Packet(NetSocket _socketCtx, int _maxBufSize = 1024)
        {
            socketCtx  = _socketCtx;
            serverTask = socketCtx.serverTask;
            socketID   = socketCtx.GetID();
            maxBufSize = _maxBufSize;

            if (_maxBufSize != 0)
            {
                buf = new byte[maxBufSize];
                Array.Clear(buf, 0, buf.Length);
            }

            packBuf.buf = buf;
            packBuf.len = maxBufSize;
        }