8017195: Introduce option to setKeepAlive parameter on CORBA sockets
authorcoffeys
Tue, 03 Sep 2013 22:35:05 +0100
changeset 19875 2283768fd093
parent 19516 589f4fdc584e
child 19876 cbf761a79b25
8017195: Introduce option to setKeepAlive parameter on CORBA sockets Reviewed-by: chegar, msheppar
corba/src/share/classes/com/sun/corba/se/impl/transport/DefaultSocketFactoryImpl.java
--- a/corba/src/share/classes/com/sun/corba/se/impl/transport/DefaultSocketFactoryImpl.java	Wed Jul 05 19:09:29 2017 +0200
+++ b/corba/src/share/classes/com/sun/corba/se/impl/transport/DefaultSocketFactoryImpl.java	Tue Sep 03 22:35:05 2013 +0100
@@ -32,6 +32,7 @@
 import java.net.ServerSocket;
 import java.nio.channels.SocketChannel;
 import java.nio.channels.ServerSocketChannel;
+import java.security.PrivilegedAction;
 
 import com.sun.corba.se.pept.transport.Acceptor;
 
@@ -44,6 +45,22 @@
     implements ORBSocketFactory
 {
     private ORB orb;
+    private static final boolean keepAlive;
+
+    static {
+        keepAlive = java.security.AccessController.doPrivileged(
+            new PrivilegedAction<Boolean>() {
+                @Override
+                public Boolean run () {
+                    String value =
+                        System.getProperty("com.sun.CORBA.transport.enableTcpKeepAlive");
+                    if (value != null)
+                        return new Boolean(!"false".equalsIgnoreCase(value));
+
+                    return Boolean.FALSE;
+                }
+            });
+    }
 
     public void setORB(ORB orb)
     {
@@ -85,6 +102,9 @@
         // Disable Nagle's algorithm (i.e., always send immediately).
         socket.setTcpNoDelay(true);
 
+        if (keepAlive)
+            socket.setKeepAlive(true);
+
         return socket;
     }
 
@@ -95,6 +115,8 @@
     {
         // Disable Nagle's algorithm (i.e., always send immediately).
         socket.setTcpNoDelay(true);
+        if (keepAlive)
+            socket.setKeepAlive(true);
     }
 }