Check if OS is capable of binding multiple sockets before creating autodiscovery sockets

This commit is contained in:
Shadowghost 2022-07-21 10:20:20 +02:00
parent b01d169d28
commit a2857c5a02

View File

@ -31,6 +31,7 @@ namespace Emby.Server.Implementations.EntryPoints
private readonly IConfiguration _config; private readonly IConfiguration _config;
private readonly IConfigurationManager _configurationManager; private readonly IConfigurationManager _configurationManager;
private readonly INetworkManager _networkManager; private readonly INetworkManager _networkManager;
private readonly bool _enableMultiSocketBinding;
/// <summary> /// <summary>
/// The UDP server. /// The UDP server.
@ -59,6 +60,7 @@ namespace Emby.Server.Implementations.EntryPoints
_config = configuration; _config = configuration;
_configurationManager = configurationManager; _configurationManager = configurationManager;
_networkManager = networkManager; _networkManager = networkManager;
_enableMultiSocketBinding = OperatingSystem.IsWindows() || OperatingSystem.IsLinux();
} }
/// <inheritdoc /> /// <inheritdoc />
@ -72,6 +74,8 @@ namespace Emby.Server.Implementations.EntryPoints
} }
try try
{
if (_enableMultiSocketBinding)
{ {
foreach (var bindAddress in _networkManager.GetInternalBindAddresses()) foreach (var bindAddress in _networkManager.GetInternalBindAddresses())
{ {
@ -85,6 +89,12 @@ namespace Emby.Server.Implementations.EntryPoints
_udpServer.Start(_cancellationTokenSource.Token); _udpServer.Start(_cancellationTokenSource.Token);
} }
} }
else
{
_udpServer = new UdpServer(_logger, _appHost, _config, System.Net.IPAddress.Any, PortNumber);
_udpServer.Start(_cancellationTokenSource.Token);
}
}
catch (SocketException ex) catch (SocketException ex)
{ {
_logger.LogWarning(ex, "Unable to start AutoDiscovery listener on UDP port {PortNumber}", PortNumber); _logger.LogWarning(ex, "Unable to start AutoDiscovery listener on UDP port {PortNumber}", PortNumber);