diff options
| author | dkanada <dkanada@users.noreply.github.com> | 2019-08-13 19:58:57 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-13 19:58:57 -0700 |
| commit | 8f8d8e3d0beaf71974b4584e9bd7ab2ad8e1683d (patch) | |
| tree | c8d4ecdfa75e6f4dc842ad3bec94041dc297e42b /Emby.Server.Implementations/Net | |
| parent | 29623d36e84bd35e5fdef91ddc6884658bf87e73 (diff) | |
| parent | a5cb069f26ed6f4f1842ceb984342a4ef9c98d08 (diff) | |
Merge pull request #1581 from Bond-009/socket1
Use System.Net abstractions instead of raw socket
Diffstat (limited to 'Emby.Server.Implementations/Net')
| -rw-r--r-- | Emby.Server.Implementations/Net/SocketFactory.cs | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/Emby.Server.Implementations/Net/SocketFactory.cs b/Emby.Server.Implementations/Net/SocketFactory.cs index 42ffa4e22..cb53ce50c 100644 --- a/Emby.Server.Implementations/Net/SocketFactory.cs +++ b/Emby.Server.Implementations/Net/SocketFactory.cs @@ -2,54 +2,12 @@ using System; using System.IO; using System.Net; using System.Net.Sockets; -using Emby.Server.Implementations.Networking; using MediaBrowser.Model.Net; namespace Emby.Server.Implementations.Net { public class SocketFactory : ISocketFactory { - // THIS IS A LINKED FILE - SHARED AMONGST MULTIPLE PLATFORMS - // Be careful to check any changes compile and work for all platform projects it is shared in. - - // Not entirely happy with this. Would have liked to have done something more generic/reusable, - // but that wasn't really the point so kept to YAGNI principal for now, even if the - // interfaces are a bit ugly, specific and make assumptions. - - public ISocket CreateTcpSocket(IPAddress remoteAddress, int remotePort) - { - if (remotePort < 0) - { - throw new ArgumentException("remotePort cannot be less than zero.", nameof(remotePort)); - } - - var addressFamily = remoteAddress.AddressFamily == AddressFamily.InterNetwork - ? AddressFamily.InterNetwork - : AddressFamily.InterNetworkV6; - - var retVal = new Socket(addressFamily, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp); - - try - { - retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); - } - catch (SocketException) - { - // This is not supported on all operating systems (qnap) - } - - try - { - return new UdpSocket(retVal, new IPEndPoint(remoteAddress, remotePort)); - } - catch - { - retVal?.Dispose(); - - throw; - } - } - /// <summary> /// Creates a new UDP acceptSocket and binds it to the specified local port. /// </summary> |
