eolivelli commented on a change in pull request #240: [SUREFIRE-1658] TCP/IP 
Channel for forked Surefire JVM. Extensions API and SPI. Polymorphism for 
remote and local process communication.
URL: https://github.com/apache/maven-surefire/pull/240#discussion_r382987085
 
 

 ##########
 File path: 
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
 ##########
 @@ -0,0 +1,123 @@
+package org.apache.maven.plugin.surefire.extensions;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.surefire.extensions.CloseableDaemonThread;
+import org.apache.maven.surefire.extensions.CommandReader;
+import org.apache.maven.surefire.extensions.EventHandler;
+import org.apache.maven.surefire.extensions.ForkChannel;
+import org.apache.maven.surefire.extensions.util.CountdownCloseable;
+import org.apache.maven.surefire.extensions.util.LineConsumerThread;
+import org.apache.maven.surefire.extensions.util.StreamFeeder;
+
+import javax.annotation.Nonnull;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketOption;
+import java.nio.channels.Channel;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.WritableByteChannel;
+
+import static java.net.StandardSocketOptions.SO_KEEPALIVE;
+import static java.net.StandardSocketOptions.SO_REUSEADDR;
+import static java.net.StandardSocketOptions.TCP_NODELAY;
+import static java.nio.channels.ServerSocketChannel.open;
+
+/**
+ *
+ */
+final class SurefireForkChannel extends ForkChannel
+{
+    private final ServerSocketChannel server;
+    private final int serverPort;
+    private SocketChannel channel;
+
+    SurefireForkChannel( int forkChannelId ) throws IOException
+    {
+        super( forkChannelId );
+        server = open();
+        setTrueOptions( SO_REUSEADDR, TCP_NODELAY, SO_KEEPALIVE );
+        server.bind( new InetSocketAddress( 0 ) );
+        serverPort = ( (InetSocketAddress) server.getLocalAddress() 
).getPort();
+    }
+
+    @Override
+    public void connectToClient() throws IOException
+    {
+        if ( channel != null )
+        {
+            throw new IllegalStateException( "already accepted TCP client 
connection" );
+        }
+        channel = server.accept();
 
 Review comment:
   > nobody knows the port in advance
   this doesn't prevent a process to discover the port
   
   > The server socket has backlog set to 1
   this is very fragile, I am talking about a possible security flaw.
   
   > We are using 127.0.0.1 and not the wild card
   This is good, but perhaps this is only for the near future
   
   > The server lasts for the run of the JVM. It is not one server. If you 
configure forkCount=5 that means 5 isolated servers and each listens to max of 
one client.
   This is a valid point, btw this can change in the future (hopefully)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to