Expose all socket settings available for the JIO connector, buffer size can make...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Oct 2008 23:28:51 +0000 (23:28 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 8 Oct 2008 23:28:51 +0000 (23:28 +0000)
Make settings consistent with those for the NIO connector, so switching between Java connectors is seamless

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@703017 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/coyote/http11/Http11Protocol.java
java/org/apache/tomcat/util/net/JIoEndpoint.java
webapps/docs/config/http.xml

index cd4cba5..b4740d4 100644 (file)
@@ -123,8 +123,12 @@ public class Http11Protocol
     /**
      * Set a property.
      */
-    public void setProperty(String name, String value) {
+    public boolean setProperty(String name, String value) {
         setAttribute(name, value);
+        if (name.startsWith("socket.")) {
+            return endpoint.setProperty(name, value);
+        }
+        return true;
     }
 
     /**
index b77e985..1dfdf38 100644 (file)
@@ -26,6 +26,7 @@ import java.util.concurrent.Executor;
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -127,11 +128,32 @@ public class JIoEndpoint {
      * Associated server socket.
      */
     protected ServerSocket serverSocket = null;
+    
+    /**
+     * Holds all the socket properties
+     */
+    protected SocketProperties socketProperties = new SocketProperties();
 
 
     // ------------------------------------------------------------- Properties
 
-
+    /**
+     * Generic properties - currently only socket.XXX properties
+     */
+    public boolean setProperty(String name, String value) {
+        final String socketName = "socket.";
+        try {
+            if (name.startsWith(socketName)) {
+                return IntrospectionUtils.setProperty(socketProperties, name.substring(socketName.length()), value);
+            } else {
+                return IntrospectionUtils.setProperty(this,name,value);
+            }
+        }catch ( Exception x ) {
+            log.error("Unable to set attribute \""+name+"\" to \""+value+"\"",x);
+            return false;
+        }
+    }
+    
     /**
      * Acceptor thread count.
      */
@@ -201,25 +223,30 @@ public class JIoEndpoint {
     /**
      * Socket TCP no delay.
      */
-    protected boolean tcpNoDelay = false;
-    public boolean getTcpNoDelay() { return tcpNoDelay; }
-    public void setTcpNoDelay(boolean tcpNoDelay) { this.tcpNoDelay = tcpNoDelay; }
+    public boolean getTcpNoDelay() { return socketProperties.getTcpNoDelay(); }
+    public void setTcpNoDelay(boolean tcpNoDelay) { socketProperties.setTcpNoDelay(tcpNoDelay); }
 
 
     /**
      * Socket linger.
      */
-    protected int soLinger = 100;
-    public int getSoLinger() { return soLinger; }
-    public void setSoLinger(int soLinger) { this.soLinger = soLinger; }
+    public int getSoLinger() {return socketProperties.getSoLingerTime();}
+    public void setSoLinger(int soLinger) { 
+        if (soLinger>=0) {
+            socketProperties.setSoLingerOn(true);
+            socketProperties.setSoLingerTime(soLinger);
+        } else {
+            socketProperties.setSoLingerOn(false);
+            socketProperties.setSoLingerTime(-1);
+        }
+    }
 
 
     /**
      * Socket timeout.
      */
-    protected int soTimeout = -1;
-    public int getSoTimeout() { return soTimeout; }
-    public void setSoTimeout(int soTimeout) { this.soTimeout = soTimeout; }
+    public int getSoTimeout() { return socketProperties.getSoTimeout(); }
+    public void setSoTimeout(int soTimeout) { socketProperties.setSoTimeout(soTimeout); }
 
 
     /**
@@ -617,16 +644,7 @@ public class JIoEndpoint {
         try {
 
             // 1: Set socket options: timeout, linger, etc
-            if (soLinger >= 0) { 
-                socket.setSoLinger(true, soLinger);
-            }
-            if (tcpNoDelay) {
-                socket.setTcpNoDelay(tcpNoDelay);
-            }
-            if (soTimeout > 0) {
-                socket.setSoTimeout(soTimeout);
-            }
-
+            socketProperties.setProperties(socket);
             // 2: SSL handshake
             step = 2;
             serverSocketFactory.handshake(socket);
index b309653..2413514 100644 (file)
     </attribute>
 
   </attributes>
+  <subsection name="Java TCP socket attributes">
+  
+      <attribute name="socket.rxBufSize" required="false">
+        <p>(int)The socket receive buffer (SO_RCVBUF) size in bytes. Default value is <code>25188</code></p>
+      </attribute>
+      <attribute name="socket.txBufSize" required="false">
+        <p>(int)The socket send buffer (SO_SNDBUF) size in bytes. Default value is <code>43800</code></p>
+      </attribute>
+      <attribute name="socket.tcpNoDelay" required="false">
+        <p>(bool)same as the standard setting <code>tcpNoDelay</code>. Default value is <code>false</code></p>
+      </attribute>
+      <attribute name="socket.soKeepAlive" required="false">
+        <p>(bool)Boolean value for the socket's keep alive setting (SO_KEEPALIVE). Default is <code>false</code>. </p>
+      </attribute>
+      <attribute name="socket.ooBInline" required="false">
+        <p>(bool)Boolean value for the socket OOBINLINE setting. Default value is <code>true</code></p>
+      </attribute>
+      <attribute name="socket.soReuseAddress" required="false">
+        <p>(bool)Boolean value for the sockets reuse address option (SO_REUSEADDR). Default value is <code>true</code></p>
+      </attribute>
+      <attribute name="socket.soLingerOn" required="false">
+        <p>(bool)Boolean value for the sockets so linger option (SO_LINGER). Default value is <code>true</code>.
+           This option is paired with the <code>soLingerTime</code> value.</p>
+      </attribute>
+      <attribute name="socket.soLingerTime" required="false">
+        <p>(bool)Value in seconds for the sockets so linger option (SO_LINGER). Default value is <code>25</code> seconds.
+           This option is paired with the soLinger value.</p>
+      </attribute>
+      <attribute name="socket.soTimeout" required="false">
+        <p>(int)Value in milliseconds for the sockets read timeout (SO_TIMEOUT). Default value is <code>5000</code> milliseconds.</p>
+      </attribute>      
+      <attribute name="socket.soTrafficClass" required="false">
+        <p>(byte)Value between <code>0</code> and <code>255</code> for the traffic class on the socket, <code>0x04 | 0x08 | 0x010</code></p>
+      </attribute>      
+      <attribute name="socket.performanceConnectionTime" required="false">
+        <p>(int)The first value for the performance settings. Default is <code>1</code>, see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)">Socket Performance Options</a></p>
+      </attribute>      
+      <attribute name="socket.performanceLatency" required="false">
+        <p>(int)The second value for the performance settings. Default is <code>0</code>, see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)">Socket Performance Options</a></p>
+      </attribute>      
+      <attribute name="socket.performanceBandwidth" required="false">
+        <p>(int)The third value for the performance settings. Default is <code>1</code>, see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)">Socket Performance Options</a></p>
+      </attribute>      
+  
+
+  </subsection>
 
   </subsection>
   
            <br/>When you are using direct buffers, make sure you allocate the appropriate amount of memory for the 
                 direct memory space. On Sun's JDK that would be something like <code>-XX:MaxDirectMemorySize=256m</code></p>
       </attribute>
-      <attribute name="socket.rxBufSize" required="false">
-        <p>(int)The socket receive buffer (SO_RCVBUF) size in bytes. Default value is <code>25188</code></p>
-      </attribute>
-      <attribute name="socket.txBufSize" required="false">
-        <p>(int)The socket send buffer (SO_SNDBUF) size in bytes. Default value is <code>43800</code></p>
-      </attribute>
       <attribute name="socket.appReadBufSize" required="false">
         <p>(int)Each connection that is opened up in Tomcat get associated with a read and a write ByteBuffer
            This attribute controls the size of these buffers. By default this read buffer is sized at <code>8192</code> bytes.
            The default is <code>500</code>.
            Other values are <code>-1</code>. unlimited cache, and <code>0</code>, no cache.</p>
       </attribute>
-      <attribute name="socket.tcpNoDelay" required="false">
-        <p>(bool)same as the standard setting <code>tcpNoDelay</code>. Default value is <code>false</code></p>
-      </attribute>
-      <attribute name="socket.soKeepAlive" required="false">
-        <p>(bool)Boolean value for the socket's keep alive setting (SO_KEEPALIVE). Default is <code>false</code>. </p>
-      </attribute>
-      <attribute name="socket.ooBInline" required="false">
-        <p>(bool)Boolean value for the socket OOBINLINE setting. Default value is <code>true</code></p>
-      </attribute>
-      <attribute name="socket.soReuseAddress" required="false">
-        <p>(bool)Boolean value for the sockets reuse address option (SO_REUSEADDR). Default value is <code>true</code></p>
-      </attribute>
-      <attribute name="socket.soLingerOn" required="false">
-        <p>(bool)Boolean value for the sockets so linger option (SO_LINGER). Default value is <code>true</code>.
-           This option is paired with the <code>soLingerTime</code> value.</p>
-      </attribute>
-      <attribute name="socket.soLingerTime" required="false">
-        <p>(bool)Value in seconds for the sockets so linger option (SO_LINGER). Default value is <code>25</code> seconds.
-           This option is paired with the soLinger value.</p>
-      </attribute>
-      <attribute name="socket.soTimeout" required="false">
-        <p>(int)Value in milliseconds for the sockets read timeout (SO_TIMEOUT). Default value is <code>5000</code> milliseconds.</p>
-      </attribute>      
-      <attribute name="socket.soTrafficClass" required="false">
-        <p>(byte)Value between <code>0</code> and <code>255</code> for the traffic class on the socket, <code>0x04 | 0x08 | 0x010</code></p>
-      </attribute>      
-      <attribute name="socket.performanceConnectionTime" required="false">
-        <p>(int)The first value for the performance settings. Default is <code>1</code>, see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)">Socket Performance Options</a></p>
-      </attribute>      
-      <attribute name="socket.performanceLatency" required="false">
-        <p>(int)The second value for the performance settings. Default is <code>0</code>, see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)">Socket Performance Options</a></p>
-      </attribute>      
-      <attribute name="socket.performanceBandwidth" required="false">
-        <p>(int)The third value for the performance settings. Default is <code>1</code>, see <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int)">Socket Performance Options</a></p>
-      </attribute>      
       <attribute name="selectorPool.maxSelectors" required="false">
         <p>(int)The max selectors to be used in the pool, to reduce selector contention.
         Use this option when the command line <code>org.apache.tomcat.util.net.NioSelectorShared</code> value is set to false.
     Classname         Http11Protocol                  Http11NioProtocol         Http11AprProtocol
     Tomcat Version   3.x 4.x 5.x 6.x                       6.x                     5.5.x 6.x
     Support Polling         NO                             YES                        YES
-    Polling Size           N/A                   Unlimited - Restricted by mem        Unlimited
-    Read HTTP Request     Blocking                     Blocking                       Blocking
-    Read HTTP Body        Blocking                     Blocking                       Blocking
-    Write HTTP Response   Blocking                     Blocking                       Blocking
+    Polling Size           N/A                   Unlimited - Restricted by mem        Unlimited - Configurable
+    Read HTTP Request     Blocking                     Non Blocking                   Blocking
+    Read HTTP Body        Blocking                     Sim Blocking                   Blocking
+    Write HTTP Response   Blocking                     Sim Blocking                   Blocking
     SSL Support           Java SSL                     Java SSL                       OpenSSL
     SSL Handshake         Blocking                     Non blocking                   Blocking
     Max Connections       maxThreads                   See polling size               See polling size