mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
fix socket errors on linux under .net core
This commit is contained in:
parent
dcd06597a7
commit
524e7facc8
@ -125,15 +125,15 @@ namespace Emby.Common.Implementations.Net
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if NETSTANDARD1_3
|
#if NET46
|
||||||
// The ExclusiveAddressUse socket option is a Windows-specific option that, when set to "true," tells Windows not to allow another socket to use the same local address as this socket
|
retVal.ExclusiveAddressUse = false;
|
||||||
// See https://github.com/dotnet/corefx/pull/11509 for more details
|
#else
|
||||||
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
|
// The ExclusiveAddressUse socket option is a Windows-specific option that, when set to "true," tells Windows not to allow another socket to use the same local address as this socket
|
||||||
|
// See https://github.com/dotnet/corefx/pull/11509 for more details
|
||||||
|
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
retVal.ExclusiveAddressUse = false;
|
retVal.ExclusiveAddressUse = false;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
retVal.ExclusiveAddressUse = false;
|
|
||||||
#endif
|
#endif
|
||||||
//retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
|
//retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
|
||||||
retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
retVal.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||||
|
@ -245,7 +245,7 @@ namespace Emby.Common.Implementations.Networking
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
return ipProperties.UnicastAddresses
|
return ipProperties.UnicastAddresses
|
||||||
.Where(i => i.IsDnsEligible)
|
//.Where(i => i.IsDnsEligible)
|
||||||
.Select(i => i.Address)
|
.Select(i => i.Address)
|
||||||
.Where(i => i.AddressFamily == AddressFamily.InterNetwork)
|
.Where(i => i.AddressFamily == AddressFamily.InterNetwork)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
@ -102,11 +102,7 @@ namespace Emby.Server.Implementations.HttpServer.SocketSharp
|
|||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
public Task SendAsync(byte[] bytes, bool endOfMessage, CancellationToken cancellationToken)
|
public Task SendAsync(byte[] bytes, bool endOfMessage, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var completionSource = new TaskCompletionSource<bool>();
|
return WebSocket.SendAsync(bytes);
|
||||||
|
|
||||||
WebSocket.SendAsync(bytes, res => completionSource.TrySetResult(true));
|
|
||||||
|
|
||||||
return completionSource.Task;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -118,11 +114,7 @@ namespace Emby.Server.Implementations.HttpServer.SocketSharp
|
|||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
public Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken)
|
public Task SendAsync(string text, bool endOfMessage, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var completionSource = new TaskCompletionSource<bool>();
|
return WebSocket.SendAsync(text);
|
||||||
|
|
||||||
WebSocket.SendAsync(text, res => completionSource.TrySetResult(true));
|
|
||||||
|
|
||||||
return completionSource.Task;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -151,9 +151,10 @@ namespace MediaBrowser.Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (client.IndexOf("web", StringComparison.OrdinalIgnoreCase) == -1 &&
|
if (client.IndexOf("web", StringComparison.OrdinalIgnoreCase) == -1 &&
|
||||||
|
|
||||||
|
// covers both emby mobile and emby for android mobile
|
||||||
client.IndexOf("mobile", StringComparison.OrdinalIgnoreCase) == -1 &&
|
client.IndexOf("mobile", StringComparison.OrdinalIgnoreCase) == -1 &&
|
||||||
client.IndexOf("ios", StringComparison.OrdinalIgnoreCase) == -1 &&
|
client.IndexOf("ios", StringComparison.OrdinalIgnoreCase) == -1 &&
|
||||||
client.IndexOf("android", StringComparison.OrdinalIgnoreCase) == -1 &&
|
|
||||||
client.IndexOf("theater", StringComparison.OrdinalIgnoreCase) == -1)
|
client.IndexOf("theater", StringComparison.OrdinalIgnoreCase) == -1)
|
||||||
{
|
{
|
||||||
options.Fields.Add(Model.Querying.ItemFields.ChildCount);
|
options.Fields.Add(Model.Querying.ItemFields.ChildCount);
|
||||||
|
@ -5,6 +5,7 @@ using System.IO;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Model.Cryptography;
|
using MediaBrowser.Model.Cryptography;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
using SocketHttpListener.Net.WebSockets;
|
using SocketHttpListener.Net.WebSockets;
|
||||||
@ -621,26 +622,22 @@ namespace SocketHttpListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendAsync(Opcode opcode, Stream stream, Action<bool> completed)
|
private Task sendAsync(Opcode opcode, Stream stream)
|
||||||
{
|
{
|
||||||
Func<Opcode, Stream, bool> sender = send;
|
var completionSource = new TaskCompletionSource<bool>();
|
||||||
sender.BeginInvoke(
|
Task.Run(() =>
|
||||||
opcode,
|
{
|
||||||
stream,
|
try
|
||||||
ar =>
|
{
|
||||||
{
|
send(opcode, stream);
|
||||||
try
|
completionSource.TrySetResult(true);
|
||||||
{
|
}
|
||||||
var sent = sender.EndInvoke(ar);
|
catch (Exception ex)
|
||||||
if (completed != null)
|
{
|
||||||
completed(sent);
|
completionSource.TrySetException(ex);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
});
|
||||||
{
|
return completionSource.Task;
|
||||||
error("An exception has occurred while callback.", ex);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// As server
|
// As server
|
||||||
@ -833,22 +830,18 @@ namespace SocketHttpListener
|
|||||||
/// <param name="data">
|
/// <param name="data">
|
||||||
/// An array of <see cref="byte"/> that represents the binary data to send.
|
/// An array of <see cref="byte"/> that represents the binary data to send.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="completed">
|
|
||||||
/// An Action<bool> delegate that references the method(s) called when the send is
|
/// An Action<bool> delegate that references the method(s) called when the send is
|
||||||
/// complete. A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
|
/// complete. A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
|
||||||
/// complete successfully; otherwise, <c>false</c>.
|
/// complete successfully; otherwise, <c>false</c>.
|
||||||
/// </param>
|
public Task SendAsync(byte[] data)
|
||||||
public void SendAsync(byte[] data, Action<bool> completed)
|
|
||||||
{
|
{
|
||||||
var msg = _readyState.CheckIfOpen() ?? data.CheckIfValidSendData();
|
var msg = _readyState.CheckIfOpen() ?? data.CheckIfValidSendData();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
{
|
{
|
||||||
error(msg);
|
throw new Exception(msg);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendAsync(Opcode.Binary, _memoryStreamFactory.CreateNew(data), completed);
|
return sendAsync(Opcode.Binary, _memoryStreamFactory.CreateNew(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -860,22 +853,18 @@ namespace SocketHttpListener
|
|||||||
/// <param name="data">
|
/// <param name="data">
|
||||||
/// A <see cref="string"/> that represents the text data to send.
|
/// A <see cref="string"/> that represents the text data to send.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="completed">
|
|
||||||
/// An Action<bool> delegate that references the method(s) called when the send is
|
/// An Action<bool> delegate that references the method(s) called when the send is
|
||||||
/// complete. A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
|
/// complete. A <see cref="bool"/> passed to this delegate is <c>true</c> if the send is
|
||||||
/// complete successfully; otherwise, <c>false</c>.
|
/// complete successfully; otherwise, <c>false</c>.
|
||||||
/// </param>
|
public Task SendAsync(string data)
|
||||||
public void SendAsync(string data, Action<bool> completed)
|
|
||||||
{
|
{
|
||||||
var msg = _readyState.CheckIfOpen() ?? data.CheckIfValidSendData();
|
var msg = _readyState.CheckIfOpen() ?? data.CheckIfValidSendData();
|
||||||
if (msg != null)
|
if (msg != null)
|
||||||
{
|
{
|
||||||
error(msg);
|
throw new Exception(msg);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sendAsync(Opcode.Text, _memoryStreamFactory.CreateNew(Encoding.UTF8.GetBytes(data)), completed);
|
return sendAsync(Opcode.Text, _memoryStreamFactory.CreateNew(Encoding.UTF8.GetBytes(data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -215,9 +215,12 @@ namespace Emby.Server
|
|||||||
|
|
||||||
var initProgress = new Progress<double>();
|
var initProgress = new Progress<double>();
|
||||||
|
|
||||||
// Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
|
if (environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows)
|
||||||
SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
|
{
|
||||||
ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
|
// Not crazy about this but it's the only way to suppress ffmpeg crash dialog boxes
|
||||||
|
SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOALIGNMENTFAULTEXCEPT |
|
||||||
|
ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
|
||||||
|
}
|
||||||
|
|
||||||
var task = _appHost.Init(initProgress);
|
var task = _appHost.Init(initProgress);
|
||||||
Task.WaitAll(task);
|
Task.WaitAll(task);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user