Exemple #1
0
        internal override async Task BindAsync(AddressBindContext context)
        {
            var exceptions = new List <Exception>();

            try
            {
                var v4Options = Clone(IPAddress.Loopback);
                await AddressBinder.BindEndpointAsync(v4Options, context).ConfigureAwait(false);
            }
            catch (Exception ex) when(!(ex is IOException))
            {
                context.Logger.LogWarning(0, "Unable to bind to {address} on the {interfaceName} interface: '{error}'.", GetDisplayName(), "IPv4 loopback", ex.Message);
                exceptions.Add(ex);
            }

            try
            {
                var v6Options = Clone(IPAddress.IPv6Loopback);
                await AddressBinder.BindEndpointAsync(v6Options, context).ConfigureAwait(false);
            }
            catch (Exception ex) when(!(ex is IOException))
            {
                context.Logger.LogWarning(0, "Unable to bind to {address} on the {interfaceName} interface: '{error}'.", GetDisplayName(), "IPv6 loopback", ex.Message);
                exceptions.Add(ex);
            }

            if (exceptions.Count == 2)
            {
                throw new IOException(GetDisplayName(), new AggregateException(exceptions));
            }

            // If StartLocalhost doesn't throw, there is at least one listener.
            // The port cannot change for "localhost".
            context.Addresses.Add(GetDisplayName());
        }
Exemple #2
0
        internal override async Task BindAsync(AddressBindContext context, CancellationToken cancellationToken)
        {
            var exceptions = new List <Exception>();

            try
            {
                var v4Options = Clone(IPAddress.Loopback);
                await AddressBinder.BindEndpointAsync(v4Options, context, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex) when(!(ex is IOException or OperationCanceledException))
            {
                context.Logger.LogInformation(0, CoreStrings.NetworkInterfaceBindingFailed, GetDisplayName(), "IPv4 loopback", ex.Message);
                exceptions.Add(ex);
            }

            try
            {
                var v6Options = Clone(IPAddress.IPv6Loopback);
                await AddressBinder.BindEndpointAsync(v6Options, context, cancellationToken).ConfigureAwait(false);
            }
            catch (Exception ex) when(!(ex is IOException or OperationCanceledException))
            {
                context.Logger.LogInformation(0, CoreStrings.NetworkInterfaceBindingFailed, GetDisplayName(), "IPv6 loopback", ex.Message);
                exceptions.Add(ex);
            }

            if (exceptions.Count == 2)
            {
                throw new IOException(CoreStrings.FormatAddressBindingFailed(GetDisplayName()), new AggregateException(exceptions));
            }

            // If StartLocalhost doesn't throw, there is at least one listener.
            // The port cannot change for "localhost".
            context.Addresses.Add(GetDisplayName());
        }
        internal override async Task BindAsync(AddressBindContext context)
        {
            var exceptions = new List <Exception>();

            try {
                var v4Options = Clone(IPAddress.Loopback);
                await AddressBinder.BindEndpointAsync(v4Options, context).ConfigureAwait(false);
            } catch (Exception ex) when(!(ex is IOException))
            {
                context.Logger.Warn($"Unable to bind to {GetDisplayName()} on the IPv4 loopback interface: '{ex.Message}'.", ex);
                exceptions.Add(ex);
            }

            try {
                var v6Options = Clone(IPAddress.IPv6Loopback);
                await AddressBinder.BindEndpointAsync(v6Options, context).ConfigureAwait(false);
            } catch (Exception ex) when(!(ex is IOException))
            {
                context.Logger.Warn($"Unable to bind to {GetDisplayName()} on the IPv6 loopback interface: '{ex.Message}'.", ex);
                exceptions.Add(ex);
            }

            if (exceptions.Count == 2)
            {
                throw new IOException($"Unable to bind to {GetDisplayName()} on the IPv4 and IPv6 loopback interfaces.", new AggregateException(exceptions));
            }
            context.Addresses.Add(GetDisplayName());
        }
Exemple #4
0
        internal virtual async Task BindAsync(AddressBindContext context)
        {
            await AddressBinder.BindEndpointAsync(this, context).ConfigureAwait(false);

            context.Addresses.Add(GetDisplayName());
        }