public virtual async ValueTask BindAsync(EndPoint endpoint, CancellationToken cancellationToken = default) { if (endpoint is IPEndPoint ipEndpoint) { _ipEndpoint = ipEndpoint; } else { throw new NotSupportedException("Only IPEndPoint are currently supported by inline sockets."); } _logger.BindListenSocket(_ipEndpoint); _listener = _networkProvider.CreateListener(new NetworkListenerSettings { IPEndPoint = _ipEndpoint, AllowNatTraversal = _options.AllowNatTraversal, ExclusiveAddressUse = _options.ExclusiveAddressUse, ListenerBacklog = _options.ListenBacklog, NoDelay = _options.NoDelay, }); // the only way to cancel a call to accept a socket is to stop the listener. // this is okay, because this call is cancelled only when the listener is about to be // unbound and disposed anyway. _listenerCancellationCallback = _listener.Stop; _listener.Start(); }
public virtual async ValueTask BindAsync(EndPoint endpoint, CancellationToken cancellationToken = default) { _endpoint = endpoint; _logger.BindListenSocket(_endpoint); _listener = _networkProvider.CreateListener(new NetworkListenerSettings { EndPoint = _endpoint, AllowNatTraversal = _options.AllowNatTraversal, ExclusiveAddressUse = _options.ExclusiveAddressUse, ListenerBacklog = _options.ListenBacklog, NoDelay = _options.NoDelay, }); // the only way to cancel a call to accept a socket is to stop the listener. // this is okay, because this call is cancelled only when the listener is about to be // unbound and disposed anyway. _listenerCancellationCallback = _listener.Stop; _listener.Start(); }