예제 #1
0
 public override byte[] Freeze()
 {
     lock (Sync)
     {
         _Incoming  = null; _Outgoing = null; Frozen = true;
         gotReqHead = gotReqBody = gotResHead = hasResBody = false;
         Base.Unpipe();
         IncomingHead.Unpipe();
         IncomingHead.OnFail -= OnSegmentFail;
         if (!gotReqHead)
         {
             IncomingHead.OnCollect -= PushIncoming;
         }
         IncomingBody.Unpipe();
         IncomingBody.Excess.Unpipe();
         IncomingBody.OnFail -= OnSegmentFail;
         if (!gotReqBody)
         {
             IncomingBody.OnFinish -= FinishIncomingMessage;
         }
         OutgoingHead.Unpipe();
         OutgoingHead.OnFail -= OnSegmentFail;
         OutgoingBody.Unpipe();
         OutgoingBody.OnFail -= OnSegmentFail;
         if (!hasResBody)
         {
             OutgoingBody.OnFinish -= FinishOutgoingMessage;
         }
         return(excess.Read());
     }
 }
예제 #2
0
 private void WaitIncoming()
 {
     lock (Sync)
     {
         _Incoming               = null; _Outgoing = null;
         gotReqHead              = gotReqBody = gotResHead = false;
         IncomingHead.OnCollect += PushIncoming;
         excess.Burst(IncomingHead);
         if (!gotReqHead)
         {
             Base.Pipe(IncomingHead);
         }
     }
 }
예제 #3
0
 public override bool FinishOutgoing()
 {
     lock (Sync)
     {
         if (!gotResHead)
         {
             return(false);
         }
         OutgoingBody.OnFinish -= FinishOutgoingMessage;
         if (!OutgoingBody.Finished)
         {
             OutgoingBody.Finish();
         }
         OutgoingBody.Unpipe();
         _Outgoing.Finish();
         _Incoming = null;
         _Outgoing = null;
         WaitIncoming();
         return(!(hasResBody = false));
     }
 }
예제 #4
0
        private void PushIncoming(RequestHead head)
        {
            lock (Sync)
            {
                gotReqHead = true;

                BodyType?type = BodyType.TryDetectFor(head, true);
                if (type == null)
                {
                    Terminate(); return;
                }
                if (!IncomingBody.TrySetFor(type.Value))
                {
                    Terminate(); return;
                }

                IncomingRequest  incoming = _Incoming = new IncomingRequest(this, head);
                OutgoingResponse outgoing = _Outgoing = new OutgoingResponse(this, head.Version);

                RequestHandler(incoming, outgoing);
                if (Ended || Frozen)
                {
                    return;
                }

                if (!IncomingBody.Finished)
                {
                    IncomingBody.Pipe(_Incoming);
                    IncomingBody.OnFinish += FinishIncomingMessage;
                    excess.Burst(IncomingBody);
                    if (!gotReqBody)
                    {
                        Base.Pipe(IncomingBody);
                    }
                }
            }
        }