rschmitt commented on code in PR #637:
URL: 
https://github.com/apache/httpcomponents-client/pull/637#discussion_r2124663608


##########
httpclient5-testing/src/test/java/org/apache/hc/client5/testing/extension/sync/UnixDomainProxyServer.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.client5.testing.extension.sync;
+
+import org.newsclub.net.unix.AFUNIXServerSocket;
+import org.newsclub.net.unix.AFUNIXSocket;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import static java.util.concurrent.CompletableFuture.supplyAsync;
+
+public final class UnixDomainProxyServer {
+    private final int port;
+    private final ExecutorService executorService;
+    private final Path socketPath;
+    private final CountDownLatch serverReady = new CountDownLatch(1);
+    private volatile AFUNIXServerSocket serverSocket;
+
+    public UnixDomainProxyServer(final int port) {
+        this.port = port;
+        this.executorService = Executors.newCachedThreadPool();
+        this.socketPath = (new File("proxy.sock")).toPath();
+    }
+
+    public void start() {
+        executorService.submit(this::runUdsProxy);
+        try {
+            serverReady.await();
+        } catch (final InterruptedException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    public Path getSocketPath() {
+        return socketPath;
+    }
+
+    public void close() {
+        try {
+            serverSocket.close();
+            executorService.shutdownNow();
+            if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) {
+                throw new RuntimeException("Failed to shut down");
+            }
+        } catch (final InterruptedException | IOException ex) {
+            throw new RuntimeException(ex);
+        }
+    }
+
+    private void runUdsProxy() {
+        try {
+            Files.deleteIfExists(socketPath);
+        } catch (final IOException ignore) {
+        }
+
+        try {
+            try (final AFUNIXServerSocket server = 
AFUNIXServerSocket.bindOn(socketPath, true)) {

Review Comment:
   OK, done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to