mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
fix network methods not shutting down
This commit is contained in:
parent
bcaf9bd19c
commit
5759ba8656
@ -43,7 +43,6 @@ namespace Mono.Nat
|
|||||||
{
|
{
|
||||||
public static class NatUtility
|
public static class NatUtility
|
||||||
{
|
{
|
||||||
private static ManualResetEvent searching;
|
|
||||||
public static event EventHandler<DeviceEventArgs> DeviceFound;
|
public static event EventHandler<DeviceEventArgs> DeviceFound;
|
||||||
public static event EventHandler<DeviceEventArgs> DeviceLost;
|
public static event EventHandler<DeviceEventArgs> DeviceLost;
|
||||||
|
|
||||||
@ -68,8 +67,6 @@ namespace Mono.Nat
|
|||||||
NatProtocol.Pmp
|
NatProtocol.Pmp
|
||||||
};
|
};
|
||||||
|
|
||||||
searching = new ManualResetEvent(false);
|
|
||||||
|
|
||||||
controllers = new List<ISearcher>();
|
controllers = new List<ISearcher>();
|
||||||
controllers.Add(PmpSearcher.Instance);
|
controllers.Add(PmpSearcher.Instance);
|
||||||
|
|
||||||
@ -86,8 +83,6 @@ namespace Mono.Nat
|
|||||||
DeviceLost(sender, args);
|
DeviceLost(sender, args);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
Task.Factory.StartNew(SearchAndListen, TaskCreationOptions.LongRunning);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void Log(string format, params object[] args)
|
internal static void Log(string format, params object[] args)
|
||||||
@ -97,12 +92,10 @@ namespace Mono.Nat
|
|||||||
logger.Debug(format, args);
|
logger.Debug(format, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task SearchAndListen()
|
private static async Task SearchAndListen(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
while (true)
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
searching.WaitOne();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var enabledProtocols = EnabledProtocols.ToList();
|
var enabledProtocols = EnabledProtocols.ToList();
|
||||||
@ -129,7 +122,7 @@ namespace Mono.Nat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async Task Receive (ISearcher searcher, List<UdpClient> clients)
|
static async Task Receive(ISearcher searcher, List<UdpClient> clients)
|
||||||
{
|
{
|
||||||
foreach (UdpClient client in clients)
|
foreach (UdpClient client in clients)
|
||||||
{
|
{
|
||||||
@ -144,22 +137,54 @@ namespace Mono.Nat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StartDiscovery ()
|
private static CancellationTokenSource _currentCancellationTokenSource;
|
||||||
|
private static object _runSyncLock = new object();
|
||||||
|
public static void StartDiscovery()
|
||||||
{
|
{
|
||||||
searching.Set();
|
lock (_runSyncLock)
|
||||||
|
{
|
||||||
|
if (_currentCancellationTokenSource == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void StopDiscovery ()
|
var tokenSource = new CancellationTokenSource();
|
||||||
|
|
||||||
|
_currentCancellationTokenSource = tokenSource;
|
||||||
|
//Task.Factory.StartNew(() => SearchAndListen(tokenSource.Token), tokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StopDiscovery()
|
||||||
{
|
{
|
||||||
searching.Reset();
|
lock (_runSyncLock)
|
||||||
|
{
|
||||||
|
var tokenSource = _currentCancellationTokenSource;
|
||||||
|
|
||||||
|
if (tokenSource != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
tokenSource.Cancel();
|
||||||
|
tokenSource.Dispose();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_currentCancellationTokenSource = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//checks if an IP address is a private address space as defined by RFC 1918
|
//checks if an IP address is a private address space as defined by RFC 1918
|
||||||
public static bool IsPrivateAddressSpace (IPAddress address)
|
public static bool IsPrivateAddressSpace(IPAddress address)
|
||||||
{
|
{
|
||||||
byte[] ba = address.GetAddressBytes ();
|
byte[] ba = address.GetAddressBytes();
|
||||||
|
|
||||||
switch ((int)ba[0]) {
|
switch ((int)ba[0])
|
||||||
|
{
|
||||||
case 10:
|
case 10:
|
||||||
return true; //10.x.x.x
|
return true; //10.x.x.x
|
||||||
case 172:
|
case 172:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user