aboutsummaryrefslogtreecommitdiff
path: root/Emby.Common.Implementations/Net/SocketFactory.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2016-11-08 14:55:32 -0500
committerGitHub <noreply@github.com>2016-11-08 14:55:32 -0500
commit82c46a84e4ce7419a92e6c5674de92d69b6ae11a (patch)
treec7263a8e6aaf43680a2de2d3ae00be15be6cd1ad /Emby.Common.Implementations/Net/SocketFactory.cs
parenta86e9fa73dd159db89efd2ae3e206f45a53c784c (diff)
parente8c70da2b6044243d8352af8358dd701afe570e5 (diff)
Merge pull request #2277 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Common.Implementations/Net/SocketFactory.cs')
-rw-r--r--Emby.Common.Implementations/Net/SocketFactory.cs37
1 files changed, 25 insertions, 12 deletions
diff --git a/Emby.Common.Implementations/Net/SocketFactory.cs b/Emby.Common.Implementations/Net/SocketFactory.cs
index bb38c72da..922b0f3cc 100644
--- a/Emby.Common.Implementations/Net/SocketFactory.cs
+++ b/Emby.Common.Implementations/Net/SocketFactory.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
+using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
namespace Emby.Common.Implementations.Net
@@ -22,16 +23,28 @@ namespace Emby.Common.Implementations.Net
/// </summary>
private IPAddress _LocalIP;
- /// <summary>
- /// Default constructor.
- /// </summary>
- /// <param name="localIP">A string containing the IP address of the local network adapter to bind sockets to. Null or empty string will use <see cref="IPAddress.Any"/>.</param>
- public SocketFactory(string localIP)
+ private ILogger _logger;
+
+ public SocketFactory(ILogger logger)
+ {
+ _logger = logger;
+ _LocalIP = IPAddress.Any;
+ }
+
+ public ISocket CreateSocket(IpAddressFamily family, MediaBrowser.Model.Net.SocketType socketType, MediaBrowser.Model.Net.ProtocolType protocolType, bool dualMode)
{
- if (String.IsNullOrEmpty(localIP))
- _LocalIP = IPAddress.Any;
- else
- _LocalIP = IPAddress.Parse(localIP);
+ var addressFamily = family == IpAddressFamily.InterNetwork
+ ? AddressFamily.InterNetwork
+ : AddressFamily.InterNetworkV6;
+
+ var socket = new Socket(addressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
+
+ if (dualMode)
+ {
+ socket.DualMode = true;
+ }
+
+ return new NetSocket(socket, _logger);
}
#region ISocketFactory Members
@@ -44,7 +57,7 @@ namespace Emby.Common.Implementations.Net
{
if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", "localPort");
- var retVal = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
+ var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
try
{
retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
@@ -68,7 +81,7 @@ namespace Emby.Common.Implementations.Net
{
if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", "localPort");
- var retVal = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
+ var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
try
{
retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
@@ -99,7 +112,7 @@ namespace Emby.Common.Implementations.Net
if (multicastTimeToLive <= 0) throw new ArgumentException("multicastTimeToLive cannot be zero or less.", "multicastTimeToLive");
if (localPort < 0) throw new ArgumentException("localPort cannot be less than zero.", "localPort");
- var retVal = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
+ var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);
try
{