-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
I'm trying to use the new SocketsHttpConnectionFactory with a unix socket. I'm inheriting from the factory:
public class UnixDomainSocketsConnectionFactory : SocketsHttpConnectionFactory
{
private readonly UnixDomainSocketEndPoint _endPoint;
public UnixDomainSocketsConnectionFactory(UnixDomainSocketEndPoint endPoint)
{
_endPoint = endPoint;
}
public override Socket CreateSocket(HttpRequestMessage message, EndPoint? endPoint, IConnectionProperties options)
{
return new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
}
public override async ValueTask<Connection> EstablishConnectionAsync(HttpRequestMessage message, EndPoint? endPoint, IConnectionProperties options, CancellationToken cancellationToken)
{
var connection = await base.EstablishConnectionAsync(message, _endPoint, options, cancellationToken);
return connection;
}
}An error is thrown when establishing the connection: SocketException: An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call.
This happens when Socket.NoDelay is set to true in EstablishConnectionAsync -
Line 79 in a1339cc
| socket.NoDelay = true; |
Right now the built-in factory can't be used with UDS. To skip that one line I would need to copy at least EstablishConnectionAsync, SocketConnection (it is internal), SocketConnectionNetworkStream and TaskSocketAsyncEventArgs into my own implementation.
Is there a way to detect whether that flag is supported? Or eat the exception if SocketException with an error code of Protocol is thrown?