bool DequeuePing(out Packet packet) { packet = null; if (PingQueue.IsEmpty) { return(false); } return(PingQueue.TryDequeue(out packet)); }
public WebSocketClient([NotNull] WebSocketListenerOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.Standards.Count == 0) { throw new ArgumentException("Empty list of WebSocket standards.", nameof(options)); } options.CheckCoherence(); this.options = options.Clone(); this.options.SetUsed(true); if (this.options.NegotiationTimeout > TimeSpan.Zero) { this.negotiationsTimeoutQueue = new CancellationQueue(this.options.NegotiationTimeout); } if (this.options.PingMode != PingMode.Manual) { this.pingQueue = new PingQueue(options.PingInterval); } this.log = this.options.Logger; this.closeEvent = new AsyncConditionSource(isSet: true) { ContinueOnCapturedContext = false }; this.workCancellationSource = new CancellationTokenSource(); this.pendingRequests = new ConcurrentDictionary <WebSocketHandshake, Task <WebSocket> >(); if (this.options.BufferManager == null) { this.options.BufferManager = BufferManager.CreateBufferManager(100, this.options.SendBufferSize * 2); // create small buffer pool if not configured } if (this.options.CertificateValidationHandler == null) { this.options.CertificateValidationHandler = this.ValidateRemoteCertificate; } }
public HttpNegotiationQueue(WebSocketFactoryCollection standards, WebSocketConnectionExtensionCollection extensions, WebSocketListenerOptions options) { if (standards == null) { throw new ArgumentNullException(nameof(standards)); } if (extensions == null) { throw new ArgumentNullException(nameof(extensions)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } this.log = options.Logger; _options = options; _extensions = extensions; _cancel = new CancellationTokenSource(); _semaphore = new SemaphoreSlim(options.ParallelNegotiations); _connections = new AsyncQueue <NetworkConnection>(options.NegotiationQueueCapacity); _negotiations = new AsyncQueue <WebSocketNegotiationResult>(); _negotiations.ParallelTakeErrorMessage = $"Parallel call to '{nameof(WebSocketListener.AcceptWebSocketAsync)}' is not allowed."; _negotiations.ClosedErrorMessage = $"{nameof(WebSocketListener)} is closed and will not accept new connections."; //_cancel.Token.Register(() => this._connections.Close(new OperationCanceledException())); _handShaker = new WebSocketHandshaker(standards, _options); if (options.PingMode != PingMode.Manual) { this.pingQueue = new PingQueue(options.PingInterval); } WorkAsync().LogFault(this.log); }
public void EnqueuePing(Packet packet) { Begin.Set(); PingQueue.Enqueue(packet); }