private void ReportOnConnectionLost(Stream connectionStream) { lock (this) { if (state == PXProtocolState.WaitingForConnection) { return; } if (!this.streamReadyTaskSource.Task.IsCompleted) { this.streamReadyTaskSource.SetException(new PXConnectionLostException(connectionStream)); } else if (!ReferenceEquals(this.streamReadyTaskSource.Task.Result, connectionStream)) { //possibly it's some new stream, so //don't wait for new connection, just try with current return; } this.streamReadyTaskSource = new TaskCompletionSource <Stream>(); state = PXProtocolState.WaitingForConnection; Task.Run(delegate { contact.OnProtocolStateChanged(); }); } }
public void SetupStream(Stream stream) { lock (this) { if (this.streamReadyTaskSource.Task.IsCompleted) { this.streamReadyTaskSource = new TaskCompletionSource <Stream>(); } state = PXProtocolState.Working; streamReadyTaskSource.SetResult(stream); } }
public void Dispose() { lock (this) { state = PXProtocolState.Disposed; this.contact = null; if (!this.streamReadyTaskSource.Task.IsCompleted) { this.streamReadyTaskSource.SetException(new PXConnectionClosedLocalException()); } } }
public StreamSetupInWrongProtocolStateException(PXProtocolState currentState) : base($"Protocol wrong state ({currentState}) to setup connection stream") { }