Esempio n. 1
0
        /// <summary>
        /// 收到fast请求
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        private Task OnFastRequest(IContenxt context)
        {
            var fastPacket = default(FastPacket);

            if (FastPacket.Parse(context.Buffer, out fastPacket) == false)
            {
                return(this.Next.Invoke(context));
            }

            if (fastPacket == null)
            {
                return(new Task(() => { }));
            }

            if (context.Session.Protocol == null)
            {
                var wrapper = new FastSession(context.Session, this);
                context.Session.SetProtocolWrapper("fast", wrapper);
            }

            var fastSession = (FastSession)context.Session.Wrapper;
            var fastPackets = this.GenerateFastPackets(context, fastPacket);

            return(new Task(() =>
            {
                foreach (var packet in fastPackets)
                {
                    var requestContext = new RequestContext(fastSession, packet, context.AllSessions);
                    this.OnRecvFastPacket(requestContext);
                }
            }));
        }
Esempio n. 2
0
        /// <summary>
        /// 收到fast请求
        /// </summary>
        /// <param name="context">上下文</param>
        /// <returns></returns>
        private Task OnFastRequestAsync(IContenxt context)
        {
            var fastPacket = default(FastPacket);

            if (FastPacket.Parse(context.InputStream, out fastPacket) == false)
            {
                return(this.Next.Invoke(context));
            }

            // 数据未完整
            if (fastPacket == null)
            {
                return(TaskExtend.CompletedTask);
            }

            if (context.Session.Protocol == Protocol.None)
            {
                var wrapper = new FastSession(context.Session, this);
                context.Session.SetProtocolWrapper(Protocol.Fast, wrapper);
            }

            var fastSession = (FastSession)context.Session.Wrapper;
            var fastPackets = this.GenerateFastPackets(context, fastPacket);

            foreach (var packet in fastPackets)
            {
                var requestContext = new RequestContext(fastSession, packet, context.AllSessions);
                this.OnRecvFastPacketAsync(requestContext);
            }
            return(TaskExtend.CompletedTask);
        }
Esempio n. 3
0
 /// <summary>
 /// 请求上下文
 /// </summary>
 /// <param name="session">当前会话对象</param>
 /// <param name="packet">数据包对象</param>
 /// <param name="allSessions">所有会话对象</param>
 internal RequestContext(FastSession session, FastPacket packet, ISessionProvider allSessions)
 {
     this.Session     = session;
     this.Packet      = packet;
     this.AllSessions = allSessions;
 }
Esempio n. 4
0
 /// <summary>
 /// 请求上下文
 /// </summary>
 /// <param name="session">当前会话对象</param>
 /// <param name="packet">数据包对象</param>
 /// <param name="allSessions">所有会话对象</param>
 internal RequestContext(FastSession session, FastPacket packet, IEnumerable <FastSession> allSessions)
 {
     this.Session     = session;
     this.Packet      = packet;
     this.AllSessions = allSessions;
 }