aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/Net/SocketFactory.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-03-29 02:25:37 -0400
committerGitHub <noreply@github.com>2017-03-29 02:25:37 -0400
commit88e3fcfdc78fcab201fad72466bf2aa50b453210 (patch)
tree1e40408a0167aa2dca47ac07b16afa26e94d18d1 /Emby.Common.Implementations/Net/SocketFactory.cs
parent75f58d5665322a5045649aed89aecfef011b315c (diff)
parent9f9e81089f5606e958bc8c3f0e4d73475d02372a (diff)
Merge pull request #2554 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Common.Implementations/Net/SocketFactory.cs')
-rw-r--r--Emby.Common.Implementations/Net/SocketFactory.cs40
1 files changed, 37 insertions, 3 deletions
diff --git a/Emby.Common.Implementations/Net/SocketFactory.cs b/Emby.Common.Implementations/Net/SocketFactory.cs
index 523f4da85..1fd367afb 100644
--- a/Emby.Common.Implementations/Net/SocketFactory.cs
+++ b/Emby.Common.Implementations/Net/SocketFactory.cs
@@ -52,6 +52,18 @@ namespace Emby.Common.Implementations.Net
{
throw new SocketCreateException(ex.SocketErrorCode.ToString(), ex);
}
+ catch (ArgumentException ex)
+ {
+ if (dualMode)
+ {
+ // Mono for BSD incorrectly throws ArgumentException instead of SocketException
+ throw new SocketCreateException("AddressFamilyNotSupported", ex);
+ }
+ else
+ {
+ throw;
+ }
+ }
}
public ISocket CreateTcpSocket(IpAddressInfo remoteAddress, int remotePort)
@@ -59,6 +71,7 @@ namespace Emby.Common.Implementations.Net
if (remotePort < 0) throw new ArgumentException("remotePort cannot be less than zero.", "remotePort");
var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
+
try
{
retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
@@ -96,10 +109,31 @@ namespace Emby.Common.Implementations.Net
}
}
+ public ISocket CreateUdpBroadcastSocket(int localPort)
+ {
+ if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", "localPort");
+
+ var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
+ try
+ {
+ retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
+ retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
+
+ return new UdpSocket(retVal, localPort, IPAddress.Any);
+ }
+ catch
+ {
+ if (retVal != null)
+ retVal.Dispose();
+
+ throw;
+ }
+ }
+
/// <summary>
- /// Creates a new UDP acceptSocket that is a member of the SSDP multicast local admin group and binds it to the specified local port.
- /// </summary>
- /// <returns>An implementation of the <see cref="ISocket"/> interface used by RSSDP components to perform acceptSocket operations.</returns>
+ /// Creates a new UDP acceptSocket that is a member of the SSDP multicast local admin group and binds it to the specified local port.
+ /// </summary>
+ /// <returns>An implementation of the <see cref="ISocket"/> interface used by RSSDP components to perform acceptSocket operations.</returns>
public ISocket CreateSsdpUdpSocket(IpAddressInfo localIpAddress, int localPort)
{
if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", "localPort");