diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-02-06 01:08:55 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-06 01:08:55 -0500 |
| commit | 2ceaa50ea737e88aca74c4af16a5c969e07d5f5a (patch) | |
| tree | f74ffd55b84f50b36f7f99b75dc10c5c27bc5b91 /Emby.Common.Implementations | |
| parent | 84d2a5303b2eee311628876851335b7b926aa2ea (diff) | |
| parent | 6f1a300bdef907415160728670726735067efc7a (diff) | |
Merge pull request #2445 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Common.Implementations')
| -rw-r--r-- | Emby.Common.Implementations/Net/UdpSocket.cs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/Emby.Common.Implementations/Net/UdpSocket.cs b/Emby.Common.Implementations/Net/UdpSocket.cs index b2af9d162..e4b0c7d6d 100644 --- a/Emby.Common.Implementations/Net/UdpSocket.cs +++ b/Emby.Common.Implementations/Net/UdpSocket.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Net; using System.Net.Sockets; using System.Security; +using System.Threading; using System.Threading.Tasks; using Emby.Common.Implementations.Networking; using MediaBrowser.Model.Net; @@ -56,7 +57,7 @@ namespace Emby.Common.Implementations.Net state.TaskCompletionSource = tcs; #if NETSTANDARD1_6 - _Socket.ReceiveFromAsync(new ArraySegment<Byte>(state.Buffer),SocketFlags.None, state.RemoteEndPoint) + _Socket.ReceiveFromAsync(new ArraySegment<Byte>(state.Buffer), SocketFlags.None, state.RemoteEndPoint) .ContinueWith((task, asyncState) => { if (task.Status != TaskStatus.Faulted) @@ -73,7 +74,7 @@ namespace Emby.Common.Implementations.Net return tcs.Task; } - public Task SendAsync(byte[] buffer, int size, IpEndPointInfo endPoint) + public Task SendAsync(byte[] buffer, int size, IpEndPointInfo endPoint, CancellationToken cancellationToken) { ThrowIfDisposed(); @@ -91,6 +92,8 @@ namespace Emby.Common.Implementations.Net buffer = copy; } + cancellationToken.ThrowIfCancellationRequested(); + _Socket.SendTo(buffer, ipEndPoint); return Task.FromResult(true); #else @@ -100,6 +103,11 @@ namespace Emby.Common.Implementations.Net { _Socket.BeginSendTo(buffer, 0, size, SocketFlags.None, ipEndPoint, result => { + if (cancellationToken.IsCancellationRequested) + { + taskSource.TrySetCanceled(); + return; + } try { _Socket.EndSend(result); |
