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

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

            // 数据未完整
            if (fastPacket == null)
            {
                var wrapper = new FastSession(context.Session, this);
                context.Session.SetProtocolWrapper(Protocol.Fast, wrapper);
                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. 2
0
 /// <summary>
 /// 请求上下文
 /// </summary>
 /// <param name="session">当前会话对象</param>
 /// <param name="packet">数据包对象</param>
 /// <param name="allSessions">所有会话对象</param>
 internal RequestContext(FastSession session, FastPacket packet, ISessionManager allSessions)
 {
     this.Session     = session;
     this.Packet      = packet;
     this.AllSessions = allSessions;
 }