private async Task ZIdleIdleAsync(int pIdleRestartInterval, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZIdleIdleAsync), pIdleRestartInterval); using (cCountdownTimer lCountdownTimer = new cCountdownTimer(pIdleRestartInterval, lContext)) { while (true) { cCommandTag lTag = new cCommandTag(); mIdleBuffer.Clear(); mIdleBuffer.AddRange(lTag); mIdleBuffer.Add(cASCII.SPACE); mIdleBuffer.AddRange(kIdleIdle); mIdleBuffer.Add(cASCII.CR); mIdleBuffer.Add(cASCII.LF); lContext.TraceVerbose("sending {0}", mIdleBuffer); mSynchroniser.InvokeNetworkSend(mIdleBuffer, lContext); await mConnection.WriteAsync(mIdleBuffer.ToArray(), mBackgroundCancellationTokenSource.Token, lContext).ConfigureAwait(false); if (await ZIdleProcessResponsesAsync(false, null, lTag, true, lContext).ConfigureAwait(false) != eIdleProcessResponsesTerminatedBy.continuerequest) { throw new cUnexpectedServerActionException(fCapabilities.idle, "idle completed before done sent", lContext); } var lProcessResponsesTerminatedBy = await ZIdleProcessResponsesAsync(true, lCountdownTimer.GetAwaitCountdownTask(), lTag, false, lContext).ConfigureAwait(false); if (lProcessResponsesTerminatedBy == eIdleProcessResponsesTerminatedBy.commandcompletion) { throw new cUnexpectedServerActionException(fCapabilities.idle, "idle completed before done sent", lContext); } mIdleBuffer.Clear(); mIdleBuffer.AddRange(kIdleDone); mIdleBuffer.Add(cASCII.CR); mIdleBuffer.Add(cASCII.LF); lContext.TraceVerbose("sending {0}", mIdleBuffer); mSynchroniser.InvokeNetworkSend(mIdleBuffer, lContext); await mConnection.WriteAsync(mIdleBuffer.ToArray(), mBackgroundCancellationTokenSource.Token, lContext).ConfigureAwait(false); await ZIdleProcessResponsesAsync(false, null, lTag, false, lContext).ConfigureAwait(false); if (lProcessResponsesTerminatedBy == eIdleProcessResponsesTerminatedBy.backgroundreleaser) { return; } lCountdownTimer.Restart(lContext); } } }
private async Task ZIdlePollAsync(int pPollInterval, cTrace.cContext pParentContext) { var lContext = pParentContext.NewMethod(nameof(cCommandPipeline), nameof(ZIdlePollAsync), pPollInterval); using (cCountdownTimer lCountdownTimer = new cCountdownTimer(pPollInterval, lContext)) { while (true) { if (mMailboxCache?.SelectedMailboxDetails != null) { await ZIdlePollCommandAsync(kIdleCheck, lContext).ConfigureAwait(false); if (mBackgroundReleaser.IsReleased(lContext)) { lContext.TraceVerbose("idle terminated during check"); return; } } await ZIdlePollCommandAsync(kIdleNoOp, lContext).ConfigureAwait(false); if (mBackgroundReleaser.IsReleased(lContext)) { lContext.TraceVerbose("idle terminated during noop"); return; } lContext.TraceVerbose("waiting"); if (await ZIdleProcessResponsesAsync(true, lCountdownTimer.GetAwaitCountdownTask(), null, false, lContext).ConfigureAwait(false) == eIdleProcessResponsesTerminatedBy.backgroundreleaser) { lContext.TraceVerbose("idle terminated during poll delay"); return; } lCountdownTimer.Restart(lContext); } } }