public HttpNegotiationQueue(WebSocketFactoryCollection standards, WebSocketConnectionExtensionCollection extensions, WebSocketListenerOptions options) { _options = options; _extensions = extensions; _cancel = new CancellationTokenSource(); _semaphore = new SemaphoreSlim(options.ParallelNegotiations); _sockets = new BufferBlock <Socket>(new DataflowBlockOptions() { BoundedCapacity = options.NegotiationQueueCapacity, CancellationToken = _cancel.Token }); _negotiations = new BufferBlock <WebSocketNegotiationResult>(new DataflowBlockOptions() { BoundedCapacity = options.NegotiationQueueCapacity, CancellationToken = _cancel.Token, }); _cancel.Token.Register(_sockets.Complete); _cancel.Token.Register(_negotiations.Complete); _handShaker = new WebSocketHandshaker(standards, _options); Task.Run((Func <Task>)WorkAsync); }
public HttpNegotiationQueue(WebSocketFactoryCollection standards, WebSocketConnectionExtensionCollection extensions, WebSocketListenerOptions options) { Guard.ParameterCannotBeNull(standards, "standards"); Guard.ParameterCannotBeNull(extensions, "extensions"); Guard.ParameterCannotBeNull(options, "options"); _options = options; _extensions = extensions; _cancel = new CancellationTokenSource(); _semaphore = new SemaphoreSlim(options.ParallelNegotiations); _sockets = new BufferBlock<Socket>(new DataflowBlockOptions() { BoundedCapacity = options.NegotiationQueueCapacity, CancellationToken = _cancel.Token }); _negotiations = new BufferBlock<WebSocketNegotiationResult>(new DataflowBlockOptions() { BoundedCapacity = options.NegotiationQueueCapacity, CancellationToken = _cancel.Token, }); _cancel.Token.Register(_sockets.Complete); _cancel.Token.Register(_negotiations.Complete); _handShaker = new WebSocketHandshaker(standards, _options); Task.Run((Func<Task>)WorkAsync); }
public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options) { Guard.ParameterCannotBeNull(endpoint, "endpoint"); Guard.ParameterCannotBeNull(options, "options"); options.CheckCoherence(); _options = options.Clone(); _cancel = new CancellationTokenSource(); #if NETSTANDARD || UAP _listener = new TcpListener(endpoint); #else if (Type.GetType("Mono.Runtime") == null && _options.UseDualStackSocket) _listener = TcpListener.Create(endpoint.Port); else _listener = new TcpListener(endpoint); #endif if (_options.UseNagleAlgorithm.HasValue) _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value; ConnectionExtensions = new WebSocketConnectionExtensionCollection(this); Standards = new WebSocketFactoryCollection(this); _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options); }
public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options) { Guard.ParameterCannotBeNull(endpoint, "endpoint"); Guard.ParameterCannotBeNull(options, "options"); options.CheckCoherence(); _options = options.Clone(); _cancel = new CancellationTokenSource(); _listener = new TcpListener(endpoint); if(_options.UseNagleAlgorithm.HasValue) _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value; ConnectionExtensions = new WebSocketConnectionExtensionCollection(this); Standards = new WebSocketFactoryCollection(this); _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options); }
public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options) { if (options == null) throw new ArgumentNullException("options"); if (endpoint == null) throw new ArgumentNullException("endpoint"); _options = options.Clone(); _cancel = new CancellationTokenSource(); _listener = new TcpListener(endpoint); ConnectionExtensions = new WebSocketConnectionExtensionCollection(this); Standards = new WebSocketFactoryCollection(this); Func<Socket, Task<WebSocketNegotiationResult>> negotiate = NegotiateWebSocket; _negotiationQueue = new TransformBlock<Socket, WebSocketNegotiationResult>(negotiate, new ExecutionDataflowBlockOptions() { CancellationToken = _cancel.Token, MaxDegreeOfParallelism = options.ParallelNegotiations, BoundedCapacity = options.NegotiationQueueCapacity }); _handShaker = new WebSocketHandshaker(Standards, _options); }
public WebSocketListener(IPEndPoint endpoint, WebSocketListenerOptions options) { if (options == null) throw new ArgumentNullException("options"); if (endpoint == null) throw new ArgumentNullException("endpoint"); options.CheckCoherence(); _options = options.Clone(); _cancel = new CancellationTokenSource(); _listener = new TcpListener(endpoint); if(_options.UseNagleAlgorithm.HasValue) _listener.Server.NoDelay = !_options.UseNagleAlgorithm.Value; ConnectionExtensions = new WebSocketConnectionExtensionCollection(this); Standards = new WebSocketFactoryCollection(this); _negotiationQueue = new HttpNegotiationQueue(Standards, ConnectionExtensions, options); }
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); }