From fc1e27b7549014dbf1de16f2805c65f8a624fb2b Mon Sep 17 00:00:00 2001 From: Patrick Barron Date: Thu, 30 Nov 2023 12:03:13 -0500 Subject: Move SocketFactory to Jellyfin.Networking --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- Emby.Server.Implementations/Net/SocketFactory.cs | 39 ------------------------ src/Jellyfin.Networking/Udp/SocketFactory.cs | 39 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 40 deletions(-) delete mode 100644 Emby.Server.Implementations/Net/SocketFactory.cs create mode 100644 src/Jellyfin.Networking/Udp/SocketFactory.cs diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 8955424099..dce56e0a4f 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -27,7 +27,6 @@ using Emby.Server.Implementations.IO; using Emby.Server.Implementations.Library; using Emby.Server.Implementations.LiveTv; using Emby.Server.Implementations.Localization; -using Emby.Server.Implementations.Net; using Emby.Server.Implementations.Playlists; using Emby.Server.Implementations.Plugins; using Emby.Server.Implementations.QuickConnect; @@ -41,6 +40,7 @@ using Jellyfin.Api.Helpers; using Jellyfin.Drawing; using Jellyfin.MediaEncoding.Hls.Playlist; using Jellyfin.Networking.Manager; +using Jellyfin.Networking.Udp; using Jellyfin.Server.Implementations; using MediaBrowser.Common; using MediaBrowser.Common.Configuration; diff --git a/Emby.Server.Implementations/Net/SocketFactory.cs b/Emby.Server.Implementations/Net/SocketFactory.cs deleted file mode 100644 index a3484f43e9..0000000000 --- a/Emby.Server.Implementations/Net/SocketFactory.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Net; -using System.Net.Sockets; -using MediaBrowser.Model.Net; - -namespace Emby.Server.Implementations.Net -{ - /// - /// Factory class to create different kinds of sockets. - /// - public class SocketFactory : ISocketFactory - { - /// - public Socket CreateUdpBroadcastSocket(int localPort) - { - if (localPort < 0) - { - throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort)); - } - - var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); - try - { - socket.EnableBroadcast = true; - socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); - socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1); - socket.Bind(new IPEndPoint(IPAddress.Any, localPort)); - - return socket; - } - catch - { - socket.Dispose(); - - throw; - } - } - } -} diff --git a/src/Jellyfin.Networking/Udp/SocketFactory.cs b/src/Jellyfin.Networking/Udp/SocketFactory.cs new file mode 100644 index 0000000000..c4e1bd0913 --- /dev/null +++ b/src/Jellyfin.Networking/Udp/SocketFactory.cs @@ -0,0 +1,39 @@ +using System; +using System.Net; +using System.Net.Sockets; +using MediaBrowser.Model.Net; + +namespace Jellyfin.Networking.Udp +{ + /// + /// Factory class to create different kinds of sockets. + /// + public class SocketFactory : ISocketFactory + { + /// + public Socket CreateUdpBroadcastSocket(int localPort) + { + if (localPort < 0) + { + throw new ArgumentException("localPort cannot be less than zero.", nameof(localPort)); + } + + var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); + try + { + socket.EnableBroadcast = true; + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1); + socket.Bind(new IPEndPoint(IPAddress.Any, localPort)); + + return socket; + } + catch + { + socket.Dispose(); + + throw; + } + } + } +} -- cgit v1.2.3