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()); } }
public override bool StartOutgoing(ResponseHead head) { lock (Sync) { if (!gotReqHead) { return(false); } BodyType?type = BodyType.TryDetectFor(head, true); if (type == null) { return(false); } if (!OutgoingBody.TrySetFor(type.Value)) { return(false); } OutgoingHead.Write(head); OutgoingHead.Burst(Base); if (!OutgoingBody.Finished) { hasResBody = true; OutgoingBody.OnFinish += FinishOutgoingMessage; OutgoingBody.Pipe(Base); _Outgoing.Pipe(OutgoingBody); } return(gotResHead = true); } }