You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by rs...@apache.org on 2025/05/29 16:07:13 UTC
(httpcomponents-core) branch master updated: SingleCoreIOReactor: Add support for Unix domain sockets
This is an automated email from the ASF dual-hosted git repository.
rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
The following commit(s) were added to refs/heads/master by this push:
new d171fcfc3 SingleCoreIOReactor: Add support for Unix domain sockets
d171fcfc3 is described below
commit d171fcfc3fbdb6530b80db5739feed66039696e3
Author: Ryan Schmitt <rs...@apache.org>
AuthorDate: Thu May 22 20:24:16 2025 -0700
SingleCoreIOReactor: Add support for Unix domain sockets
This commit teaches `SingleCoreIOReactor` to recognize when the remote
address of a session request is for a JEP 380 Unix-domain socket and
open the corresponding type of `SocketChannel`. This is done using
reflection, since the underlying feature was added in JDK16.
---
.../org/apache/hc/core5/reactor/SingleCoreIOReactor.java | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
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 2442f355b..c56d3adc7 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);