mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 17:14:42 +01:00
improve ipv6 error handling
This commit is contained in:
@@ -13,7 +13,9 @@ namespace Emby.Common.Implementations.Net
|
||||
public Socket Socket { get; private set; }
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public NetSocket(Socket socket, ILogger logger)
|
||||
public bool DualMode { get; private set; }
|
||||
|
||||
public NetSocket(Socket socket, ILogger logger, bool isDualMode)
|
||||
{
|
||||
if (socket == null)
|
||||
{
|
||||
@@ -26,6 +28,7 @@ namespace Emby.Common.Implementations.Net
|
||||
|
||||
Socket = socket;
|
||||
_logger = logger;
|
||||
DualMode = isDualMode;
|
||||
}
|
||||
|
||||
public IpEndPointInfo LocalEndPoint
|
||||
@@ -81,7 +84,7 @@ namespace Emby.Common.Implementations.Net
|
||||
private SocketAcceptor _acceptor;
|
||||
public void StartAccept(Action<ISocket> onAccept, Func<bool> isClosed)
|
||||
{
|
||||
_acceptor = new SocketAcceptor(_logger, Socket, onAccept, isClosed);
|
||||
_acceptor = new SocketAcceptor(_logger, Socket, onAccept, isClosed, DualMode);
|
||||
|
||||
_acceptor.StartAccept();
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ namespace Emby.Common.Implementations.Net
|
||||
private readonly Socket _originalSocket;
|
||||
private readonly Func<bool> _isClosed;
|
||||
private readonly Action<ISocket> _onAccept;
|
||||
private readonly bool _isDualMode;
|
||||
|
||||
public SocketAcceptor(ILogger logger, Socket originalSocket, Action<ISocket> onAccept, Func<bool> isClosed)
|
||||
public SocketAcceptor(ILogger logger, Socket originalSocket, Action<ISocket> onAccept, Func<bool> isClosed, bool isDualMode)
|
||||
{
|
||||
if (logger == null)
|
||||
{
|
||||
@@ -34,6 +35,7 @@ namespace Emby.Common.Implementations.Net
|
||||
_logger = logger;
|
||||
_originalSocket = originalSocket;
|
||||
_isClosed = isClosed;
|
||||
_isDualMode = isDualMode;
|
||||
_onAccept = onAccept;
|
||||
}
|
||||
|
||||
@@ -115,7 +117,7 @@ namespace Emby.Common.Implementations.Net
|
||||
if (acceptSocket != null)
|
||||
{
|
||||
//ProcessAccept(acceptSocket);
|
||||
_onAccept(new NetSocket(acceptSocket, _logger));
|
||||
_onAccept(new NetSocket(acceptSocket, _logger, _isDualMode));
|
||||
}
|
||||
|
||||
// Accept the next connection request
|
||||
|
||||
@@ -46,21 +46,11 @@ namespace Emby.Common.Implementations.Net
|
||||
socket.DualMode = true;
|
||||
}
|
||||
|
||||
return new NetSocket(socket, _logger);
|
||||
return new NetSocket(socket, _logger, dualMode);
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
if (dualMode)
|
||||
{
|
||||
_logger.Error("Error creating dual mode socket: {0}. Will retry with ipv4-only.", ex.SocketErrorCode);
|
||||
|
||||
if (ex.SocketErrorCode == SocketError.AddressFamilyNotSupported)
|
||||
{
|
||||
return CreateSocket(IpAddressFamily.InterNetwork, socketType, protocolType, false);
|
||||
}
|
||||
}
|
||||
|
||||
throw;
|
||||
throw new SocketCreateException(ex.SocketErrorCode.ToString(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user