|
@@ -1,4 +1,5 @@
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
+using MediaBrowser.Dlna.Server;
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
using System;
|
|
|
using System.Collections.Concurrent;
|
|
@@ -10,72 +11,199 @@ using System.Net.Sockets;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
|
|
|
-namespace MediaBrowser.Dlna.Server
|
|
|
+namespace MediaBrowser.Dlna.Ssdp
|
|
|
{
|
|
|
public class SsdpHandler : IDisposable
|
|
|
{
|
|
|
- private readonly AutoResetEvent _datagramPosted = new AutoResetEvent(false);
|
|
|
- private readonly ConcurrentQueue<Datagram> _messageQueue = new ConcurrentQueue<Datagram>();
|
|
|
+ private Socket _socket;
|
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
private readonly IServerConfigurationManager _config;
|
|
|
- private readonly string _serverSignature;
|
|
|
- private bool _isDisposed;
|
|
|
|
|
|
const string SSDPAddr = "239.255.255.250";
|
|
|
const int SSDPPort = 1900;
|
|
|
+ private readonly string _serverSignature;
|
|
|
|
|
|
- private readonly IPEndPoint _ssdpEndp = new IPEndPoint(IPAddress.Parse(SSDPAddr), SSDPPort);
|
|
|
private readonly IPAddress _ssdpIp = IPAddress.Parse(SSDPAddr);
|
|
|
-
|
|
|
- private UdpClient _udpClient;
|
|
|
-
|
|
|
- private readonly Dictionary<Guid, List<UpnpDevice>> _devices = new Dictionary<Guid, List<UpnpDevice>>();
|
|
|
+ private readonly IPEndPoint _ssdpEndp = new IPEndPoint(IPAddress.Parse(SSDPAddr), SSDPPort);
|
|
|
|
|
|
private Timer _queueTimer;
|
|
|
private Timer _notificationTimer;
|
|
|
+
|
|
|
+ private readonly AutoResetEvent _datagramPosted = new AutoResetEvent(false);
|
|
|
+ private readonly ConcurrentQueue<Datagram> _messageQueue = new ConcurrentQueue<Datagram>();
|
|
|
|
|
|
+ private bool _isDisposed;
|
|
|
+ private readonly ConcurrentDictionary<Guid, List<UpnpDevice>> _devices = new ConcurrentDictionary<Guid, List<UpnpDevice>>();
|
|
|
+
|
|
|
public SsdpHandler(ILogger logger, IServerConfigurationManager config, string serverSignature)
|
|
|
{
|
|
|
_logger = logger;
|
|
|
_config = config;
|
|
|
_serverSignature = serverSignature;
|
|
|
+ }
|
|
|
+
|
|
|
+ public event EventHandler<SsdpMessageEventArgs> MessageReceived;
|
|
|
|
|
|
- Start();
|
|
|
+ private void OnMessageReceived(SsdpMessageEventArgs args)
|
|
|
+ {
|
|
|
+ if (string.Equals(args.Method, "M-SEARCH", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ RespondToSearch(args.EndPoint, args.Headers["st"]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public IEnumerable<UpnpDevice> Devices
|
|
|
+ public IEnumerable<UpnpDevice> RegisteredDevices
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
- UpnpDevice[] devs;
|
|
|
- lock (_devices)
|
|
|
- {
|
|
|
- devs = _devices.Values.SelectMany(i => i).ToArray();
|
|
|
- }
|
|
|
- return devs;
|
|
|
+ return _devices.Values.SelectMany(i => i).ToList();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private void Start()
|
|
|
+
|
|
|
+ public void Start()
|
|
|
{
|
|
|
- _udpClient = new UdpClient();
|
|
|
- _udpClient.Client.UseOnlyOverlappedIO = true;
|
|
|
- _udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
|
|
- _udpClient.ExclusiveAddressUse = false;
|
|
|
- _udpClient.Client.Bind(new IPEndPoint(IPAddress.Any, SSDPPort));
|
|
|
- _udpClient.JoinMulticastGroup(_ssdpIp, 2);
|
|
|
+ _socket = CreateMulticastSocket();
|
|
|
+
|
|
|
_logger.Info("SSDP service started");
|
|
|
Receive();
|
|
|
|
|
|
StartNotificationTimer();
|
|
|
}
|
|
|
|
|
|
+ public void SendDatagram(string header,
|
|
|
+ Dictionary<string, string> values,
|
|
|
+ IPAddress localAddress,
|
|
|
+ int sendCount = 1)
|
|
|
+ {
|
|
|
+ SendDatagram(header, values, _ssdpEndp, localAddress, sendCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SendDatagram(string header,
|
|
|
+ Dictionary<string, string> values,
|
|
|
+ IPEndPoint endpoint,
|
|
|
+ IPAddress localAddress,
|
|
|
+ int sendCount = 1)
|
|
|
+ {
|
|
|
+ var msg = new SsdpMessageBuilder().BuildMessage(header, values);
|
|
|
+
|
|
|
+ var dgram = new Datagram(endpoint, localAddress, _logger, msg, sendCount);
|
|
|
+ if (_messageQueue.Count == 0)
|
|
|
+ {
|
|
|
+ dgram.Send();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ _messageQueue.Enqueue(dgram);
|
|
|
+ StartQueueTimer();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SendDatagramFromDevices(string header,
|
|
|
+ Dictionary<string, string> values,
|
|
|
+ IPEndPoint endpoint,
|
|
|
+ string deviceType)
|
|
|
+ {
|
|
|
+ foreach (var d in RegisteredDevices)
|
|
|
+ {
|
|
|
+ if (string.Equals(deviceType, "ssdp:all", StringComparison.OrdinalIgnoreCase) ||
|
|
|
+ string.Equals(deviceType, d.Type, StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ SendDatagram(header, values, endpoint, d.Address);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void RespondToSearch(IPEndPoint endpoint, string deviceType)
|
|
|
+ {
|
|
|
+ if (_config.Configuration.DlnaOptions.EnableDebugLogging)
|
|
|
+ {
|
|
|
+ _logger.Debug("RespondToSearch");
|
|
|
+ }
|
|
|
+
|
|
|
+ const string header = "HTTP/1.1 200 OK";
|
|
|
+
|
|
|
+ foreach (var d in RegisteredDevices)
|
|
|
+ {
|
|
|
+ if (string.Equals(deviceType, "ssdp:all", StringComparison.OrdinalIgnoreCase) ||
|
|
|
+ string.Equals(deviceType, d.Type, StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
+
|
|
|
+ values["CACHE-CONTROL"] = "max-age = 600";
|
|
|
+ values["DATE"] = DateTime.Now.ToString("R");
|
|
|
+ values["EXT"] = "";
|
|
|
+ values["LOCATION"] = d.Descriptor.ToString();
|
|
|
+ values["SERVER"] = _serverSignature;
|
|
|
+ values["ST"] = d.Type;
|
|
|
+ values["USN"] = d.USN;
|
|
|
+
|
|
|
+ SendDatagram(header, values, endpoint, d.Address);
|
|
|
+
|
|
|
+ _logger.Info("{1} - Responded to a {0} request to {2}", d.Type, endpoint, d.Address.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private readonly object _queueTimerSyncLock = new object();
|
|
|
+ private void StartQueueTimer()
|
|
|
+ {
|
|
|
+ lock (_queueTimerSyncLock)
|
|
|
+ {
|
|
|
+ if (_queueTimer == null)
|
|
|
+ {
|
|
|
+ _queueTimer = new Timer(QueueTimerCallback, null, 1000, Timeout.Infinite);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _queueTimer.Change(1000, Timeout.Infinite);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void QueueTimerCallback(object state)
|
|
|
+ {
|
|
|
+ while (_messageQueue.Count != 0)
|
|
|
+ {
|
|
|
+ Datagram msg;
|
|
|
+ if (!_messageQueue.TryPeek(out msg))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (msg != null && (!_isDisposed || msg.TotalSendCount > 1))
|
|
|
+ {
|
|
|
+ msg.Send();
|
|
|
+ if (msg.SendCount > msg.TotalSendCount)
|
|
|
+ {
|
|
|
+ _messageQueue.TryDequeue(out msg);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ _messageQueue.TryDequeue(out msg);
|
|
|
+ }
|
|
|
+
|
|
|
+ _datagramPosted.Set();
|
|
|
+
|
|
|
+ if (_messageQueue.Count > 0)
|
|
|
+ {
|
|
|
+ StartQueueTimer();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DisposeQueueTimer();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void Receive()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- _udpClient.BeginReceive(ReceiveCallback, null);
|
|
|
+ var buffer = new byte[1024];
|
|
|
+
|
|
|
+ EndPoint endpoint = new IPEndPoint(IPAddress.Any, SSDPPort);
|
|
|
+
|
|
|
+ _socket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref endpoint, ReceiveCallback, buffer);
|
|
|
}
|
|
|
catch (ObjectDisposedException)
|
|
|
{
|
|
@@ -84,10 +212,16 @@ namespace MediaBrowser.Dlna.Server
|
|
|
|
|
|
private void ReceiveCallback(IAsyncResult result)
|
|
|
{
|
|
|
+ if (_isDisposed)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
try
|
|
|
{
|
|
|
- var endpoint = new IPEndPoint(IPAddress.None, SSDPPort);
|
|
|
- var received = _udpClient.EndReceive(result, ref endpoint);
|
|
|
+ EndPoint endpoint = new IPEndPoint(IPAddress.Any, SSDPPort);
|
|
|
+ var receivedCount = _socket.EndReceiveFrom(result, ref endpoint);
|
|
|
+ var received = (byte[])result.AsyncState;
|
|
|
|
|
|
if (_config.Configuration.DlnaOptions.EnableDebugLogging)
|
|
|
{
|
|
@@ -98,7 +232,7 @@ namespace MediaBrowser.Dlna.Server
|
|
|
{
|
|
|
var proto = (reader.ReadLine() ?? string.Empty).Trim();
|
|
|
var method = proto.Split(new[] { ' ' }, 2)[0];
|
|
|
- var headers = new Headers();
|
|
|
+ var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
|
|
|
{
|
|
|
line = line.Trim();
|
|
@@ -119,10 +253,12 @@ namespace MediaBrowser.Dlna.Server
|
|
|
_logger.Debug("{0} - Datagram method: {1}", endpoint, method);
|
|
|
}
|
|
|
|
|
|
- if (string.Equals(method, "M-SEARCH", StringComparison.OrdinalIgnoreCase))
|
|
|
+ OnMessageReceived(new SsdpMessageEventArgs
|
|
|
{
|
|
|
- RespondToSearch(endpoint, headers["st"]);
|
|
|
- }
|
|
|
+ Method = method,
|
|
|
+ Headers = headers,
|
|
|
+ EndPoint = (IPEndPoint)endpoint
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -130,105 +266,60 @@ namespace MediaBrowser.Dlna.Server
|
|
|
_logger.ErrorException("Failed to read SSDP message", ex);
|
|
|
}
|
|
|
|
|
|
- if (!_isDisposed)
|
|
|
+ if (_socket != null)
|
|
|
{
|
|
|
Receive();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void RespondToSearch(IPEndPoint endpoint, string req)
|
|
|
+ public void Dispose()
|
|
|
{
|
|
|
- if (string.Equals(req, "ssdp:all", StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- req = null;
|
|
|
- }
|
|
|
-
|
|
|
- if (_config.Configuration.DlnaOptions.EnableDebugLogging)
|
|
|
- {
|
|
|
- _logger.Debug("RespondToSearch");
|
|
|
- }
|
|
|
-
|
|
|
- foreach (var d in Devices)
|
|
|
+ _isDisposed = true;
|
|
|
+ while (_messageQueue.Count != 0)
|
|
|
{
|
|
|
- if (!string.IsNullOrEmpty(req) && !string.Equals(req, d.Type, StringComparison.OrdinalIgnoreCase))
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- SendSearchResponse(endpoint, d);
|
|
|
+ _datagramPosted.WaitOne();
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- private void SendSearchResponse(IPEndPoint endpoint, UpnpDevice dev)
|
|
|
- {
|
|
|
- var builder = new StringBuilder();
|
|
|
-
|
|
|
- const string argFormat = "{0}: {1}\r\n";
|
|
|
|
|
|
- builder.Append("HTTP/1.1 200 OK\r\n");
|
|
|
- builder.AppendFormat(argFormat, "CACHE-CONTROL", "max-age = 600");
|
|
|
- builder.AppendFormat(argFormat, "DATE", DateTime.Now.ToString("R"));
|
|
|
- builder.AppendFormat(argFormat, "EXT", "");
|
|
|
- builder.AppendFormat(argFormat, "LOCATION", dev.Descriptor);
|
|
|
- builder.AppendFormat(argFormat, "SERVER", _serverSignature);
|
|
|
- builder.AppendFormat(argFormat, "ST", dev.Type);
|
|
|
- builder.AppendFormat(argFormat, "USN", dev.USN);
|
|
|
- builder.Append("\r\n");
|
|
|
-
|
|
|
- SendDatagram(endpoint, dev.Address, builder.ToString(), false);
|
|
|
+ DisposeSocket();
|
|
|
+ DisposeQueueTimer();
|
|
|
+ DisposeNotificationTimer();
|
|
|
|
|
|
- _logger.Info("{1} - Responded to a {0} request to {2}", dev.Type, endpoint, dev.Address.ToString());
|
|
|
+ _datagramPosted.Dispose();
|
|
|
}
|
|
|
|
|
|
- private void SendDatagram(IPEndPoint endpoint, IPAddress localAddress, string msg, bool sticky)
|
|
|
+ private void DisposeSocket()
|
|
|
{
|
|
|
- if (_isDisposed)
|
|
|
+ if (_socket != null)
|
|
|
{
|
|
|
- return;
|
|
|
+ _socket.Close();
|
|
|
+ _socket.Dispose();
|
|
|
+ _socket = null;
|
|
|
}
|
|
|
-
|
|
|
- var dgram = new Datagram(endpoint, localAddress, _logger, msg, sticky);
|
|
|
- if (_messageQueue.Count == 0)
|
|
|
- {
|
|
|
- dgram.Send();
|
|
|
- }
|
|
|
- _messageQueue.Enqueue(dgram);
|
|
|
- StartQueueTimer();
|
|
|
}
|
|
|
|
|
|
- private void QueueTimerCallback(object state)
|
|
|
+ private void DisposeQueueTimer()
|
|
|
{
|
|
|
- while (_messageQueue.Count != 0)
|
|
|
+ lock (_queueTimerSyncLock)
|
|
|
{
|
|
|
- Datagram msg;
|
|
|
- if (!_messageQueue.TryPeek(out msg))
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (msg != null && (!_isDisposed || msg.Sticky))
|
|
|
+ if (_queueTimer != null)
|
|
|
{
|
|
|
- msg.Send();
|
|
|
- if (msg.SendCount > 2)
|
|
|
- {
|
|
|
- _messageQueue.TryDequeue(out msg);
|
|
|
- }
|
|
|
- break;
|
|
|
+ _queueTimer.Dispose();
|
|
|
+ _queueTimer = null;
|
|
|
}
|
|
|
-
|
|
|
- _messageQueue.TryDequeue(out msg);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- _datagramPosted.Set();
|
|
|
+ private Socket CreateMulticastSocket()
|
|
|
+ {
|
|
|
+ var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
|
|
+ socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
|
|
|
+ socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
|
|
+ socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 4);
|
|
|
+ socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(_ssdpIp, 0));
|
|
|
|
|
|
- if (_messageQueue.Count > 0)
|
|
|
- {
|
|
|
- StartQueueTimer();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DisposeQueueTimer();
|
|
|
- }
|
|
|
+ socket.Bind(new IPEndPoint(IPAddress.Any, SSDPPort));
|
|
|
+
|
|
|
+ return socket;
|
|
|
}
|
|
|
|
|
|
private void NotifyAll()
|
|
@@ -237,121 +328,64 @@ namespace MediaBrowser.Dlna.Server
|
|
|
{
|
|
|
_logger.Debug("Sending alive notifications");
|
|
|
}
|
|
|
- foreach (var d in Devices)
|
|
|
+ foreach (var d in RegisteredDevices)
|
|
|
{
|
|
|
- NotifyDevice(d, "alive", false);
|
|
|
+ NotifyDevice(d, "alive");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void NotifyDevice(UpnpDevice dev, string type, bool sticky)
|
|
|
+ private void NotifyDevice(UpnpDevice dev, string type, int sendCount = 1)
|
|
|
{
|
|
|
- var builder = new StringBuilder();
|
|
|
+ const string header = "NOTIFY * HTTP/1.1";
|
|
|
|
|
|
- const string argFormat = "{0}: {1}\r\n";
|
|
|
+ var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
- builder.Append("NOTIFY * HTTP/1.1\r\n{0}\r\n");
|
|
|
- builder.AppendFormat(argFormat, "HOST", "239.255.255.250:1900");
|
|
|
- builder.AppendFormat(argFormat, "CACHE-CONTROL", "max-age = 600");
|
|
|
- builder.AppendFormat(argFormat, "LOCATION", dev.Descriptor);
|
|
|
- builder.AppendFormat(argFormat, "SERVER", _serverSignature);
|
|
|
- builder.AppendFormat(argFormat, "NTS", "ssdp:" + type);
|
|
|
- builder.AppendFormat(argFormat, "NT", dev.Type);
|
|
|
- builder.AppendFormat(argFormat, "USN", dev.USN);
|
|
|
- builder.Append("\r\n");
|
|
|
+ // If needed later for non-server devices, these headers will need to be dynamic
|
|
|
+ values["HOST"] = "239.255.255.250:1900";
|
|
|
+ values["CACHE-CONTROL"] = "max-age = 600";
|
|
|
+ values["LOCATION"] = dev.Descriptor.ToString();
|
|
|
+ values["SERVER"] = _serverSignature;
|
|
|
+ values["NTS"] = "ssdp:" + type;
|
|
|
+ values["NT"] = dev.Type;
|
|
|
+ values["USN"] = dev.USN;
|
|
|
|
|
|
if (_config.Configuration.DlnaOptions.EnableDebugLogging)
|
|
|
{
|
|
|
_logger.Debug("{0} said {1}", dev.USN, type);
|
|
|
}
|
|
|
|
|
|
- SendDatagram(_ssdpEndp, dev.Address, builder.ToString(), sticky);
|
|
|
+ SendDatagram(header, values, dev.Address, sendCount);
|
|
|
}
|
|
|
|
|
|
- public void RegisterNotification(Guid uuid, Uri descriptor, IPAddress address)
|
|
|
+ public void RegisterNotification(Guid uuid, Uri descriptionUri, IPAddress address, IEnumerable<string> services)
|
|
|
{
|
|
|
List<UpnpDevice> list;
|
|
|
lock (_devices)
|
|
|
{
|
|
|
if (!_devices.TryGetValue(uuid, out list))
|
|
|
{
|
|
|
- _devices.Add(uuid, list = new List<UpnpDevice>());
|
|
|
+ _devices.TryAdd(uuid, list = new List<UpnpDevice>());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- foreach (var t in new[]
|
|
|
- {
|
|
|
- "upnp:rootdevice",
|
|
|
- "urn:schemas-upnp-org:device:MediaServer:1",
|
|
|
- "urn:schemas-upnp-org:service:ContentDirectory:1",
|
|
|
- "uuid:" + uuid
|
|
|
- })
|
|
|
- {
|
|
|
- list.Add(new UpnpDevice(uuid, t, descriptor, address));
|
|
|
- }
|
|
|
+ list.AddRange(services.Select(i => new UpnpDevice(uuid, i, descriptionUri, address)));
|
|
|
|
|
|
NotifyAll();
|
|
|
- _logger.Debug("Registered mount {0} at {1}", uuid, descriptor);
|
|
|
+ _logger.Debug("Registered mount {0} at {1}", uuid, descriptionUri);
|
|
|
}
|
|
|
|
|
|
- private void UnregisterNotification(Guid uuid)
|
|
|
+ public void UnregisterNotification(Guid uuid)
|
|
|
{
|
|
|
List<UpnpDevice> dl;
|
|
|
- lock (_devices)
|
|
|
+ if (_devices.TryRemove(uuid, out dl))
|
|
|
{
|
|
|
- if (!_devices.TryGetValue(uuid, out dl))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- _devices.Remove(uuid);
|
|
|
- }
|
|
|
- foreach (var d in dl)
|
|
|
- {
|
|
|
- NotifyDevice(d, "byebye", true);
|
|
|
- }
|
|
|
- _logger.Debug("Unregistered mount {0}", uuid);
|
|
|
- }
|
|
|
-
|
|
|
- public void Dispose()
|
|
|
- {
|
|
|
- _isDisposed = true;
|
|
|
- while (_messageQueue.Count != 0)
|
|
|
- {
|
|
|
- _datagramPosted.WaitOne();
|
|
|
- }
|
|
|
|
|
|
- _udpClient.DropMulticastGroup(_ssdpIp);
|
|
|
- _udpClient.Close();
|
|
|
-
|
|
|
- DisposeNotificationTimer();
|
|
|
- DisposeQueueTimer();
|
|
|
- _datagramPosted.Dispose();
|
|
|
- }
|
|
|
-
|
|
|
- private readonly object _queueTimerSyncLock = new object();
|
|
|
- private void StartQueueTimer()
|
|
|
- {
|
|
|
- lock (_queueTimerSyncLock)
|
|
|
- {
|
|
|
- if (_queueTimer == null)
|
|
|
- {
|
|
|
- _queueTimer = new Timer(QueueTimerCallback, null, 1000, Timeout.Infinite);
|
|
|
- }
|
|
|
- else
|
|
|
+ foreach (var d in dl.ToList())
|
|
|
{
|
|
|
- _queueTimer.Change(1000, Timeout.Infinite);
|
|
|
+ NotifyDevice(d, "byebye", 2);
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- private void DisposeQueueTimer()
|
|
|
- {
|
|
|
- lock (_queueTimerSyncLock)
|
|
|
- {
|
|
|
- if (_queueTimer != null)
|
|
|
- {
|
|
|
- _queueTimer.Dispose();
|
|
|
- _queueTimer = null;
|
|
|
- }
|
|
|
+ _logger.Debug("Unregistered mount {0}", uuid);
|
|
|
}
|
|
|
}
|
|
|
|