aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2022-03-08 22:20:43 +0100
committerBond_009 <bond.009@outlook.com>2022-03-08 22:20:43 +0100
commit1d018c557599a544ad2f8193ce7cc0a6a6f1260a (patch)
treecb493215dd8bb83e0ecf022224e6f8f6342fa5d1
parent03f1eff21abf75d88d15df05b6a841e48943c7ef (diff)
SocketFactory: Remove redundant code
ExclusiveAddressUse should be false by default afaik
-rw-r--r--Emby.Server.Implementations/Net/SocketFactory.cs20
-rw-r--r--MediaBrowser.Model/Net/ISocketFactory.cs2
-rw-r--r--RSSDP/SsdpCommunicationsServer.cs2
3 files changed, 4 insertions, 20 deletions
diff --git a/Emby.Server.Implementations/Net/SocketFactory.cs b/Emby.Server.Implementations/Net/SocketFactory.cs
index fd3fc31c9..58fa14948 100644
--- a/Emby.Server.Implementations/Net/SocketFactory.cs
+++ b/Emby.Server.Implementations/Net/SocketFactory.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
#pragma warning disable CS1591
using System;
@@ -63,18 +61,13 @@ namespace Emby.Server.Implementations.Net
}
/// <inheritdoc />
- public ISocket CreateUdpMulticastSocket(string ipAddress, int multicastTimeToLive, int localPort)
+ public ISocket CreateUdpMulticastSocket(IPAddress ipAddress, int multicastTimeToLive, int localPort)
{
if (ipAddress == null)
{
throw new ArgumentNullException(nameof(ipAddress));
}
- if (ipAddress.Length == 0)
- {
- throw new ArgumentException("ipAddress cannot be an empty string.", nameof(ipAddress));
- }
-
if (multicastTimeToLive <= 0)
{
throw new ArgumentException("multicastTimeToLive cannot be zero or less.", nameof(multicastTimeToLive));
@@ -89,15 +82,6 @@ namespace Emby.Server.Implementations.Net
try
{
- // not supported on all platforms. throws on ubuntu with .net core 2.0
- retVal.ExclusiveAddressUse = false;
- }
- catch (SocketException)
- {
- }
-
- try
- {
// seeing occasional exceptions thrown on qnap
// System.Net.Sockets.SocketException (0x80004005): Protocol not available
retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
@@ -114,7 +98,7 @@ namespace Emby.Server.Implementations.Net
var localIp = IPAddress.Any;
- retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse(ipAddress), localIp));
+ retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ipAddress, localIp));
retVal.MulticastLoopback = true;
return new UdpSocket(retVal, localPort, localIp);
diff --git a/MediaBrowser.Model/Net/ISocketFactory.cs b/MediaBrowser.Model/Net/ISocketFactory.cs
index 1527ef595..a2835b711 100644
--- a/MediaBrowser.Model/Net/ISocketFactory.cs
+++ b/MediaBrowser.Model/Net/ISocketFactory.cs
@@ -26,6 +26,6 @@ namespace MediaBrowser.Model.Net
/// <param name="multicastTimeToLive">The multicast time to live value. Actually a maximum number of network hops for UDP packets.</param>
/// <param name="localPort">The local port to bind to.</param>
/// <returns>A <see cref="ISocket"/> implementation.</returns>
- ISocket CreateUdpMulticastSocket(string ipAddress, int multicastTimeToLive, int localPort);
+ ISocket CreateUdpMulticastSocket(IPAddress ipAddress, int multicastTimeToLive, int localPort);
}
}
diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs
index a66b70ac1..6e4f5634d 100644
--- a/RSSDP/SsdpCommunicationsServer.cs
+++ b/RSSDP/SsdpCommunicationsServer.cs
@@ -338,7 +338,7 @@ namespace Rssdp.Infrastructure
private ISocket ListenForBroadcastsAsync()
{
- var socket = _SocketFactory.CreateUdpMulticastSocket(SsdpConstants.MulticastLocalAdminAddress, _MulticastTtl, SsdpConstants.MulticastPort);
+ var socket = _SocketFactory.CreateUdpMulticastSocket(IPAddress.Parse(SsdpConstants.MulticastLocalAdminAddress), _MulticastTtl, SsdpConstants.MulticastPort);
_ = ListenToSocketInternal(socket);
return socket;