improve socket disposal

pull/702/head
Luke Pulverenti 9 years ago
parent 6c62c20a9e
commit 34b72a98cf

@ -109,30 +109,31 @@ namespace MediaBrowser.Dlna.Ssdp
var endPoint = new IPEndPoint(localIp, 1900);
var socket = GetMulticastSocket(localIp, endPoint);
var receiveBuffer = new byte[64000];
CreateNotifier(localIp);
while (!_tokenSource.IsCancellationRequested)
using (var socket = GetMulticastSocket(localIp, endPoint))
{
var receivedBytes = await socket.ReceiveAsync(receiveBuffer, 0, 64000);
var receiveBuffer = new byte[64000];
CreateNotifier(localIp);
if (receivedBytes > 0)
while (!_tokenSource.IsCancellationRequested)
{
var args = SsdpHelper.ParseSsdpResponse(receiveBuffer);
args.EndPoint = endPoint;
args.LocalEndPoint = new IPEndPoint(localIp, 0);
var receivedBytes = await socket.ReceiveAsync(receiveBuffer, 0, 64000);
if (_ssdpHandler.IgnoreMessage(args, true))
if (receivedBytes > 0)
{
return;
}
var args = SsdpHelper.ParseSsdpResponse(receiveBuffer);
args.EndPoint = endPoint;
args.LocalEndPoint = new IPEndPoint(localIp, 0);
if (_ssdpHandler.IgnoreMessage(args, true))
{
return;
}
_ssdpHandler.LogMessageReceived(args, true);
_ssdpHandler.LogMessageReceived(args, true);
TryCreateDevice(args);
TryCreateDevice(args);
}
}
}

Loading…
Cancel
Save