The Free Software Media System - Server Backend & API
Added logging and broadcast = true
BaronGreenback5b0c1829084b
diff --git a/Emby.Server.Implementations/Net/SocketFactory.cs b/Emby.Server.Implementations/Net/SocketFactory.csindex 1777216584..bed79a9adc 100644--- a/Emby.Server.Implementations/Net/SocketFactory.cs+++ b/Emby.Server.Implementations/Net/SocketFactory.cs@@ -4,6 +4,7 @@ using System;using System.Net;using System.Net.Sockets;using MediaBrowser.Model.Net;+using Microsoft.Extensions.Logging;namespace Emby.Server.Implementations.Net{@@ -67,7 +68,7 @@ namespace Emby.Server.Implementations.Net/// <param name="multicastTimeToLive">The multicast time to live value for the acceptSocket.</param>/// <param name="localPort">The number of the local port to bind to.</param>/// <returns></returns>- public ISocket CreateUdpMulticastSocket(string ipAddress, int multicastTimeToLive, int localPort)+ public ISocket CreateUdpMulticastSocket(string ipAddress, int multicastTimeToLive, int localPort, ILogger _logger){if (ipAddress == null){@@ -89,6 +90,8 @@ namespace Emby.Server.Implementations.Netthrow new ArgumentException("localPort cannot be less than zero.", nameof(localPort));}+ _logger.LogError("Created");+var retVal = new Socket(AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp);try@@ -100,6 +103,8 @@ namespace Emby.Server.Implementations.Net{}+ _logger.LogError("Exclusive false");+try{// seeing occasional exceptions thrown on qnap@@ -110,8 +115,14 @@ namespace Emby.Server.Implementations.Net{}+ _logger.LogError("Reused");+try{+ retVal.EnableBroadcast = true; // CHANGE++ _logger.LogError("Broadcast");+// retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);retVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, multicastTimeToLive);@@ -120,6 +131,8 @@ namespace Emby.Server.Implementations.NetretVal.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse(ipAddress), localIp));retVal.MulticastLoopback = true;+ _logger.LogError("Sorted");+return new UdpSocket(retVal, localPort, localIp);}catchdiff --git a/MediaBrowser.Model/Net/ISocketFactory.cs b/MediaBrowser.Model/Net/ISocketFactory.csindex 363abefc19..3a19590a9b 100644--- a/MediaBrowser.Model/Net/ISocketFactory.cs+++ b/MediaBrowser.Model/Net/ISocketFactory.cs@@ -1,6 +1,7 @@#pragma warning disable CS1591using System.Net;+using Microsoft.Extensions.Logging;namespace MediaBrowser.Model.Net{@@ -22,7 +23,9 @@ namespace MediaBrowser.Model.Net/// <param name="ipAddress">The multicast IP address to bind to.</param>/// <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>+ /// <param name="logger"></param>/// <returns>A <see cref="ISocket"/> implementation.</returns>- ISocket CreateUdpMulticastSocket(string ipAddress, int multicastTimeToLive, int localPort);+ ISocket CreateUdpMulticastSocket(string ipAddress, int multicastTimeToLive, int localPort, ILogger logger);+}}diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.csindex 8fde700e0c..34b67a945f 100644--- a/RSSDP/SsdpCommunicationsServer.cs+++ b/RSSDP/SsdpCommunicationsServer.cs@@ -338,9 +338,12 @@ namespace Rssdp.Infrastructureprivate ISocket ListenForBroadcastsAsync(){- var socket = _SocketFactory.CreateUdpMulticastSocket(SsdpConstants.MulticastLocalAdminAddress, _MulticastTtl, SsdpConstants.MulticastPort);+ var socket = _SocketFactory.CreateUdpMulticastSocket(SsdpConstants.MulticastLocalAdminAddress, _MulticastTtl, SsdpConstants.MulticastPort, _logger);- _ = ListenToSocketInternal(socket);+ // TODO: remove this try and logging - testing purposes only.+ _logger.LogError("Socket Created.");++ _ = ListenToSocketInternal(socket, _logger);return socket;}@@ -374,16 +377,16 @@ namespace Rssdp.Infrastructureforeach (var socket in sockets){- _ = ListenToSocketInternal(socket);+ _ = ListenToSocketInternal(socket, _logger);}return sockets;}- private async Task ListenToSocketInternal(ISocket socket)+ private async Task ListenToSocketInternal(ISocket socket, ILogger logger){var cancelled = false;- var receiveBuffer = new byte[8192];+ var receiveBuffer = new byte[8192];while (!cancelled && !IsDisposed){@@ -393,6 +396,7 @@ namespace Rssdp.Infrastructureif (result.ReceivedBytes > 0){+ _logger.LogError("processing...");// Strange cannot convert compiler error here if I don't explicitly// assign or cast to Action first. Assignment is easier to read,// so went with that.