/// <summary> /// Starts server with a specified client SSL validation timeout /// </summary> /// <param name="endpoint">local endpoint start server</param> /// <param name="validationTimeout">Client SSL validation timeout</param> /// <returns>Server task</returns> public Task StartServer(IPEndPoint endpoint, TimeSpan validationTimeout) { if (this.cancellationTokenSource != null) { SecureTransportEventSource.Log.StartServerFailed_AlreadyStarted(this.transportId); throw SecureTransportException.AlreadyStarted(); } this.cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(this.rootCancellationToken); this.hasStarted.Reset(); this.hasStopped.Reset(); SecureTransportEventSource.Log.StartServer(this.transportId, endpoint.ToString()); var task = Task.Run(() => this.StartListening(endpoint, validationTimeout), this.cancellationTokenSource.Token); if (!this.hasStarted.Wait(DefaultStartTimeout)) { SecureTransportEventSource.Log.StartTimedout(this.transportId); throw SecureTransportException.StartTimedout(); } return(task); }
/// <summary> /// Starts client with a specified server SSL validation timeout /// </summary> /// <param name="validationTimeout">Connection SSL validation timeout</param> /// <param name="endpoints">Endpoints to connect to</param> /// <returns>Client task</returns> public Task StartClient(TimeSpan validationTimeout, params IPEndPoint[] endpoints) { if (this.cancellationTokenSource != null) { SecureTransportEventSource.Log.StartClientFailed_AlreadyStarted(this.transportId); throw SecureTransportException.AlreadyStarted(); } this.cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(this.rootCancellationToken); this.hasStarted.Reset(); this.hasStopped.Reset(); SecureTransportEventSource.Log.StartClient(this.transportId, endpoints.Length); var task = Task.Run(() => this.StartConnecting(endpoints, validationTimeout), this.cancellationTokenSource.Token); if (!this.hasStarted.Wait(DefaultStartTimeout)) { SecureTransportEventSource.Log.StartTimedout(this.transportId); throw SecureTransportException.StartTimedout(); } return(task); }