mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-07 11:57:55 +02:00
commit
d0af746823
3 changed files with 56 additions and 26 deletions
|
@ -32,6 +32,8 @@ namespace Emby.Common.Implementations.Net
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISocket CreateSocket(IpAddressFamily family, MediaBrowser.Model.Net.SocketType socketType, MediaBrowser.Model.Net.ProtocolType protocolType, bool dualMode)
|
public ISocket CreateSocket(IpAddressFamily family, MediaBrowser.Model.Net.SocketType socketType, MediaBrowser.Model.Net.ProtocolType protocolType, bool dualMode)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var addressFamily = family == IpAddressFamily.InterNetwork
|
var addressFamily = family == IpAddressFamily.InterNetwork
|
||||||
? AddressFamily.InterNetwork
|
? AddressFamily.InterNetwork
|
||||||
|
@ -46,6 +48,21 @@ namespace Emby.Common.Implementations.Net
|
||||||
|
|
||||||
return new NetSocket(socket, _logger);
|
return new NetSocket(socket, _logger);
|
||||||
}
|
}
|
||||||
|
catch (SocketException ex)
|
||||||
|
{
|
||||||
|
if (dualMode)
|
||||||
|
{
|
||||||
|
_logger.Error("Error creating dual mode socket: {0}. Will retry with ipv4-only.", ex.SocketErrorCode);
|
||||||
|
|
||||||
|
if (ex.SocketErrorCode == SocketError.AddressFamilyNotSupported)
|
||||||
|
{
|
||||||
|
return CreateSocket(IpAddressFamily.InterNetwork, socketType, protocolType, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region ISocketFactory Members
|
#region ISocketFactory Members
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,9 @@ namespace Emby.Dlna.Main
|
||||||
{
|
{
|
||||||
if (_communicationsServer == null)
|
if (_communicationsServer == null)
|
||||||
{
|
{
|
||||||
_communicationsServer = new SsdpCommunicationsServer(_socketFactory, _networkManager, _logger)
|
var enableMultiSocketBinding = _environmentInfo.OperatingSystem == OperatingSystem.Windows;
|
||||||
|
|
||||||
|
_communicationsServer = new SsdpCommunicationsServer(_socketFactory, _networkManager, _logger, enableMultiSocketBinding)
|
||||||
{
|
{
|
||||||
IsShared = true
|
IsShared = true
|
||||||
};
|
};
|
||||||
|
|
|
@ -52,6 +52,7 @@ namespace Rssdp.Infrastructure
|
||||||
private int _MulticastTtl;
|
private int _MulticastTtl;
|
||||||
|
|
||||||
private bool _IsShared;
|
private bool _IsShared;
|
||||||
|
private readonly bool _enableMultiSocketBinding;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -75,8 +76,8 @@ namespace Rssdp.Infrastructure
|
||||||
/// Minimum constructor.
|
/// Minimum constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="System.ArgumentNullException">The <paramref name="socketFactory"/> argument is null.</exception>
|
/// <exception cref="System.ArgumentNullException">The <paramref name="socketFactory"/> argument is null.</exception>
|
||||||
public SsdpCommunicationsServer(ISocketFactory socketFactory, INetworkManager networkManager, ILogger logger)
|
public SsdpCommunicationsServer(ISocketFactory socketFactory, INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding)
|
||||||
: this(socketFactory, 0, SsdpConstants.SsdpDefaultMulticastTimeToLive, networkManager, logger)
|
: this(socketFactory, 0, SsdpConstants.SsdpDefaultMulticastTimeToLive, networkManager, logger, enableMultiSocketBinding)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ namespace Rssdp.Infrastructure
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="System.ArgumentNullException">The <paramref name="socketFactory"/> argument is null.</exception>
|
/// <exception cref="System.ArgumentNullException">The <paramref name="socketFactory"/> argument is null.</exception>
|
||||||
/// <exception cref="System.ArgumentOutOfRangeException">The <paramref name="multicastTimeToLive"/> argument is less than or equal to zero.</exception>
|
/// <exception cref="System.ArgumentOutOfRangeException">The <paramref name="multicastTimeToLive"/> argument is less than or equal to zero.</exception>
|
||||||
public SsdpCommunicationsServer(ISocketFactory socketFactory, int localPort, int multicastTimeToLive, INetworkManager networkManager, ILogger logger)
|
public SsdpCommunicationsServer(ISocketFactory socketFactory, int localPort, int multicastTimeToLive, INetworkManager networkManager, ILogger logger, bool enableMultiSocketBinding)
|
||||||
{
|
{
|
||||||
if (socketFactory == null) throw new ArgumentNullException("socketFactory");
|
if (socketFactory == null) throw new ArgumentNullException("socketFactory");
|
||||||
if (multicastTimeToLive <= 0) throw new ArgumentOutOfRangeException("multicastTimeToLive", "multicastTimeToLive must be greater than zero.");
|
if (multicastTimeToLive <= 0) throw new ArgumentOutOfRangeException("multicastTimeToLive", "multicastTimeToLive must be greater than zero.");
|
||||||
|
@ -102,6 +103,7 @@ namespace Rssdp.Infrastructure
|
||||||
_MulticastTtl = multicastTimeToLive;
|
_MulticastTtl = multicastTimeToLive;
|
||||||
_networkManager = networkManager;
|
_networkManager = networkManager;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_enableMultiSocketBinding = enableMultiSocketBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -199,17 +201,23 @@ namespace Rssdp.Infrastructure
|
||||||
if (fromLocalIpAddress.AddressFamily == IpAddressFamily.InterNetwork)
|
if (fromLocalIpAddress.AddressFamily == IpAddressFamily.InterNetwork)
|
||||||
{
|
{
|
||||||
sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.Any) || fromLocalIpAddress.Equals(i.LocalIPAddress));
|
sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.Any) || fromLocalIpAddress.Equals(i.LocalIPAddress));
|
||||||
}
|
|
||||||
else if (fromLocalIpAddress.AddressFamily == IpAddressFamily.InterNetworkV6)
|
|
||||||
{
|
|
||||||
sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.IPv6Any) || fromLocalIpAddress.Equals(i.LocalIPAddress));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If sending to the loopback address, filter the socket list as well
|
// If sending to the loopback address, filter the socket list as well
|
||||||
if (destination.IpAddress.Equals(IpAddressInfo.Loopback))
|
if (destination.IpAddress.Equals(IpAddressInfo.Loopback))
|
||||||
{
|
{
|
||||||
sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.Any) || i.LocalIPAddress.Equals(IpAddressInfo.Loopback));
|
sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.Any) || i.LocalIPAddress.Equals(IpAddressInfo.Loopback));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (fromLocalIpAddress.AddressFamily == IpAddressFamily.InterNetworkV6)
|
||||||
|
{
|
||||||
|
sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.IPv6Any) || fromLocalIpAddress.Equals(i.LocalIPAddress));
|
||||||
|
|
||||||
|
// If sending to the loopback address, filter the socket list as well
|
||||||
|
if (destination.IpAddress.Equals(IpAddressInfo.IPv6Loopback))
|
||||||
|
{
|
||||||
|
sockets = sockets.Where(i => i.LocalIPAddress.Equals(IpAddressInfo.IPv6Any) || i.LocalIPAddress.Equals(IpAddressInfo.IPv6Loopback));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sockets.ToList();
|
return sockets.ToList();
|
||||||
}
|
}
|
||||||
|
@ -353,6 +361,8 @@ namespace Rssdp.Infrastructure
|
||||||
|
|
||||||
sockets.Add(_SocketFactory.CreateSsdpUdpSocket(IpAddressInfo.Any, _LocalPort));
|
sockets.Add(_SocketFactory.CreateSsdpUdpSocket(IpAddressInfo.Any, _LocalPort));
|
||||||
|
|
||||||
|
if (_enableMultiSocketBinding)
|
||||||
|
{
|
||||||
foreach (var address in _networkManager.GetLocalIpAddresses().ToList())
|
foreach (var address in _networkManager.GetLocalIpAddresses().ToList())
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -364,6 +374,7 @@ namespace Rssdp.Infrastructure
|
||||||
_logger.ErrorException("Error in CreateSsdpUdpSocket. IPAddress: {0}", ex, address);
|
_logger.ErrorException("Error in CreateSsdpUdpSocket. IPAddress: {0}", ex, address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var socket in sockets)
|
foreach (var socket in sockets)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue