diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java index 2442f355b3..c56d3adc70 100644 --- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java +++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/SingleCoreIOReactor.java @@ -29,9 +29,11 @@ import java.io.IOException; import java.net.InetSocketAddress; +import java.net.ProtocolFamily; import java.net.Socket; import java.net.SocketAddress; import java.net.SocketOption; +import java.net.StandardProtocolFamily; import java.net.StandardSocketOptions; import java.net.UnknownHostException; import java.nio.channels.CancelledKeyException; @@ -346,7 +348,7 @@ private void processPendingConnectionRequests() { if (!sessionRequest.isCancelled()) { final SocketChannel socketChannel; try { - socketChannel = SocketChannel.open(); + socketChannel = openSocketFor(sessionRequest.remoteAddress); } catch (final IOException ex) { sessionRequest.failed(ex); return; @@ -361,6 +363,18 @@ private void processPendingConnectionRequests() { } } + private static SocketChannel openSocketFor(final SocketAddress remoteAddress) throws IOException { + if (remoteAddress instanceof InetSocketAddress) { + return SocketChannel.open(); + } + try { + return (SocketChannel) SocketChannel.class.getMethod("open", ProtocolFamily.class) + .invoke(null, StandardProtocolFamily.valueOf("UNIX")); + } catch (final ReflectiveOperationException e) { + throw new UnsupportedOperationException("UNIX-family socket channels not supported", e); + } + } + private void processConnectionRequest(final SocketChannel socketChannel, final IOSessionRequest sessionRequest) throws IOException { socketChannel.configureBlocking(false); prepareSocket(socketChannel);