mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 00:55:13 +01:00
update main projects
This commit is contained in:
@@ -139,30 +139,58 @@ namespace Emby.Server.Implementations.Udp
|
||||
{
|
||||
_udpClient = _socketFactory.CreateUdpSocket(port);
|
||||
|
||||
Task.Run(() => StartListening());
|
||||
Task.Run(() => BeginReceive());
|
||||
}
|
||||
|
||||
private async void StartListening()
|
||||
{
|
||||
while (!_isDisposed)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = await _udpClient.ReceiveAsync(CancellationToken.None).ConfigureAwait(false);
|
||||
private readonly byte[] _receiveBuffer = new byte[8192];
|
||||
|
||||
OnMessageReceived(result);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
private void BeginReceive()
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var result = _udpClient.BeginReceive(_receiveBuffer, 0, _receiveBuffer.Length, OnReceiveResult);
|
||||
|
||||
if (result.CompletedSynchronously)
|
||||
{
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error receiving udp message", ex);
|
||||
OnReceiveResult(result);
|
||||
}
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error receiving udp message", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReceiveResult(IAsyncResult result)
|
||||
{
|
||||
if (_isDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var socketResult = _udpClient.EndReceive(result);
|
||||
|
||||
OnMessageReceived(socketResult);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error receiving udp message", ex);
|
||||
}
|
||||
|
||||
BeginReceive();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -239,13 +267,13 @@ namespace Emby.Server.Implementations.Udp
|
||||
|
||||
try
|
||||
{
|
||||
await _udpClient.SendWithLockAsync(bytes, bytes.Length, remoteEndPoint, CancellationToken.None).ConfigureAwait(false);
|
||||
await _udpClient.SendToAsync(bytes, 0, bytes.Length, remoteEndPoint, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
_logger.Info("Udp message sent to {0}", remoteEndPoint);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user