示例#1
0
        void ConnectedServerTask(object data)
        {
            Packet    packet    = (Packet)data;
            NetSocket socketCtx = packet.socketCtx;
            Server    server    = GetServer();

            if (CheckingPacketVaild(packet) == 0)
            {
                return;
            }

            if (socketCtx.sock.Connected == false)
            {
                SocketError(socketCtx);
                return;
            }

            socketCtx.sock.EndConnect(packet.ar);
            socketCtx.SetSocketState(SocketState.CONNECTED_SERVER);
            socketCtx.UpdataTimeStamp();

            int bufSize = socketCtx.dePacketor.GetMaxBufferSize();

            if (packet.packBuf.len != bufSize)
            {
                packet = socketCtx.CreatePacket(bufSize);
            }

            socketCtx.dePacketor.UnPack(SocketEvent.EV_SOCKET_CONNECTED, socketCtx);
            server.IocpPostRecv(packet);
        }
示例#2
0
        void RecvedTask(object data)
        {
            Packet    packet    = (Packet)data;
            NetSocket socketCtx = packet.socketCtx;
            Server    server    = GetServer();

            if (CheckingPacketVaild(packet) == 0)
            {
                return;
            }

            SocketError socketError = System.Net.Sockets.SocketError.Success;

            packet.transferedBytes = socketCtx.sock.EndReceive(packet.ar, out socketError);

            if (socketError != System.Net.Sockets.SocketError.Success)
            {
                SocketError(socketCtx);
                return;
            }

            socketCtx.UpdataTimeStamp();

            if (socketCtx.dataTransMode == DataTransMode.MODE_PACK)
            {
                socketCtx.dePacketor.SetCurtPack(socketCtx, packet.buf, packet.transferedBytes);
                int ret = socketCtx.dePacketor.Extract();

                if (ret == 2)
                {
                    socketCtx.SetSocketState(SocketState.RECV_DATA_TOO_BIG);
                    SocketError(socketCtx.GetID());
                }
            }
            else
            {
                socketCtx.SetPack(packet.buf, 0, packet.transferedBytes);
                socketCtx.dePacketor.UnPack(SocketEvent.EV_SOCKET_RECV, socketCtx);
                socketCtx.RemovePack();
            }

            // 然后开始投递下一个WSARecv请求
            server.IocpPostRecv(packet);
        }
示例#3
0
        void AcceptedClientTask(object data)
        {
            Packet    packet    = (Packet)data;
            NetSocket socketCtx = packet.socketCtx;
            Server    server    = GetServer();

            // 把这个有效的客户端信息,加入到socketMap中去
            socketMap[socketCtx.GetID()] = socketCtx;

            socketCtx.SetPack(packet.buf, 0, packet.transferedBytes);
            socketCtx.dePacketor.UnPack(SocketEvent.EV_SOCKET_ACCEPTED, socketCtx);
            socketCtx.RemovePack();

            int bufSize = socketCtx.dePacketor.GetMaxBufferSize();

            if (packet.packBuf.len != bufSize)
            {
                packet = socketCtx.CreatePacket(bufSize);
            }

            server.IocpPostRecv(packet);
        }