From 982ea98325be2edb99371d99fd64d2f21db7dca9 Mon Sep 17 00:00:00 2001 From: markt Date: Wed, 29 Oct 2008 12:35:59 +0000 Subject: [PATCH] r703017 broke SSL with the JIO connector on Windows (and possibly other platforms). The problem was that some settings don't make sense for an SSL socket so rather than ignoring them a SocketExcpetion is thrown. With this patch, only attributes set by the user are passed to the socket and if setting the attribute throws an exception it is logged as an error. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@708892 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/net/JIoEndpoint.java | 17 +- .../apache/tomcat/util/net/SocketProperties.java | 173 ++++++++++++--------- webapps/docs/config/http.xml | 49 ++++-- 3 files changed, 140 insertions(+), 99 deletions(-) diff --git a/java/org/apache/tomcat/util/net/JIoEndpoint.java b/java/org/apache/tomcat/util/net/JIoEndpoint.java index fc2ccd66d..15986ee1b 100644 --- a/java/org/apache/tomcat/util/net/JIoEndpoint.java +++ b/java/org/apache/tomcat/util/net/JIoEndpoint.java @@ -640,22 +640,21 @@ public class JIoEndpoint { */ protected boolean setSocketOptions(Socket socket) { // Process the connection - int step = 1; + try { - // 1: Set socket options: timeout, linger, etc socketProperties.setProperties(socket); + } catch (Throwable t) { + log.error(sm.getString("endpoint.err.unexpected"), t); + // Close the socket + return false; + } + try { // 2: SSL handshake - step = 2; serverSocketFactory.handshake(socket); - } catch (Throwable t) { if (log.isDebugEnabled()) { - if (step == 2) { - log.debug(sm.getString("endpoint.err.handshake"), t); - } else { - log.debug(sm.getString("endpoint.err.unexpected"), t); - } + log.debug(sm.getString("endpoint.err.handshake"), t); } // Tell to close the socket return false; diff --git a/java/org/apache/tomcat/util/net/SocketProperties.java b/java/org/apache/tomcat/util/net/SocketProperties.java index ef3029bd2..4401deeef 100644 --- a/java/org/apache/tomcat/util/net/SocketProperties.java +++ b/java/org/apache/tomcat/util/net/SocketProperties.java @@ -18,6 +18,7 @@ package org.apache.tomcat.util.net; import java.net.Socket; import java.net.SocketException; + /** * Properties that can be set in the <Connector> element * in server.xml. All properties are prefixed with "socket." @@ -44,8 +45,6 @@ public class SocketProperties { */ protected int processorCache = 500; - - /** * Enable/disable poller event cache, this bounded cache stores * PollerEvent objects to reduce GC for the poller @@ -56,22 +55,23 @@ public class SocketProperties { */ protected int eventCache = 500; - /** * Enable/disable direct buffers for the network buffers * Default value is enabled */ protected boolean directBuffer = false; + /** - * Socket receive buffer size in bytes (SO_RCVBUF) - * Default value is 25188 + * Socket receive buffer size in bytes (SO_RCVBUF). + * JVM default used if not set. */ - protected int rxBufSize = 25188; + protected Integer rxBufSize = null; + /** - * Socket send buffer size in bytes (SO_SNDBUF) - * Default value is 43800 + * Socket send buffer size in bytes (SO_SNDBUF). + * JVM default used if not set. */ - protected int txBufSize = 43800; + protected Integer txBufSize = null; /** * The application read buffer size in bytes. @@ -93,7 +93,6 @@ public class SocketProperties { */ protected int bufferPool = 500; - /** * Buffer pool size in bytes to be cached * -1 means unlimited, 0 means no cache @@ -102,60 +101,75 @@ public class SocketProperties { protected int bufferPoolSize = 1024*1024*100; /** - * TCP_NO_DELAY option, default is true + * TCP_NO_DELAY option. JVM default used if not set. */ - protected boolean tcpNoDelay = true; + protected Boolean tcpNoDelay = null; + /** - * SO_KEEPALIVE option, default is false + * SO_KEEPALIVE option. JVM default used if not set. */ - protected boolean soKeepAlive = false; + protected Boolean soKeepAlive = null; + /** - * OOBINLINE option, default is true + * OOBINLINE option. JVM default used if not set. */ - protected boolean ooBInline = true; + protected Boolean ooBInline = null; + /** - * SO_REUSEADDR option, default is true + * SO_REUSEADDR option. JVM default used if not set. */ - protected boolean soReuseAddress = true; + protected Boolean soReuseAddress = null; + /** - * SO_LINGER option, default is true, paired with the soLingerTime value + * SO_LINGER option, paired with the soLingerTime value. + * JVM defaults used unless both attributes are set. */ - protected boolean soLingerOn = true; + protected Boolean soLingerOn = null; + /** - * SO_LINGER option, default is 25 seconds. + * SO_LINGER option, paired with the soLingerOn value. + * JVM defaults used unless both attributes are set. */ - protected int soLingerTime = 25; + protected Integer soLingerTime = null; + /** - * SO_TIMEOUT option, default is 5000 milliseconds + * SO_TIMEOUT option. JVM default used if not set. */ - protected int soTimeout = 5000; + protected Integer soTimeout = null; + /** * Traffic class option, value between 0 and 255 * IPTOS_LOWCOST (0x02) * IPTOS_RELIABILITY (0x04) * IPTOS_THROUGHPUT (0x08) * IPTOS_LOWDELAY (0x10) - * Default value is 0x04 | 0x08 | 0x010 + * JVM default used if not set */ - protected int soTrafficClass = 0x04 | 0x08 | 0x010; + protected Integer soTrafficClass = null; + /** * Performance preferences according to * http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int) - * Default value is 1 + * All three performance attributes must be set or the JVM defaults will be + * used. */ - protected int performanceConnectionTime = 1; + protected Integer performanceConnectionTime = null; + /** * Performance preferences according to * http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int) - * Default value is 0 + * All three performance attributes must be set or the JVM defaults will be + * used. */ - protected int performanceLatency = 0; + protected Integer performanceLatency = null; + /** * Performance preferences according to * http://java.sun.com/j2se/1.5.0/docs/api/java/net/Socket.html#setPerformancePreferences(int,%20int,%20int) - * Default value is 1 + * All three performance attributes must be set or the JVM defaults will be + * used. */ - protected int performanceBandwidth = 1; + protected Integer performanceBandwidth = null; /** * The minimum frequency of the timeout interval to avoid the @@ -163,20 +177,32 @@ public class SocketProperties { */ protected long timeoutInterval = 1000; - - private Socket properties; - public void setProperties(Socket socket) throws SocketException{ - socket.setReceiveBufferSize(rxBufSize); - socket.setSendBufferSize(txBufSize); - socket.setOOBInline(ooBInline); - socket.setKeepAlive(soKeepAlive); - socket.setPerformancePreferences(performanceConnectionTime,performanceLatency,performanceBandwidth); - socket.setReuseAddress(soReuseAddress); - socket.setSoLinger(soLingerOn,soLingerTime); - socket.setSoTimeout(soTimeout); - socket.setTcpNoDelay(tcpNoDelay); - socket.setTrafficClass(soTrafficClass); + if (rxBufSize != null) + socket.setReceiveBufferSize(rxBufSize.intValue()); + if (txBufSize != null) + socket.setSendBufferSize(txBufSize.intValue()); + if (ooBInline !=null) + socket.setOOBInline(ooBInline.booleanValue()); + if (soKeepAlive != null) + socket.setKeepAlive(soKeepAlive.booleanValue()); + if (performanceConnectionTime != null && performanceLatency != null && + performanceBandwidth != null) + socket.setPerformancePreferences( + performanceConnectionTime.intValue(), + performanceLatency.intValue(), + performanceBandwidth.intValue()); + if (soReuseAddress != null) + socket.setReuseAddress(soReuseAddress.booleanValue()); + if (soLingerOn != null && soLingerTime != null) + socket.setSoLinger(soLingerOn.booleanValue(), + soLingerTime.intValue()); + if (soTimeout != null) + socket.setSoTimeout(soTimeout.intValue()); + if (tcpNoDelay != null) + socket.setTcpNoDelay(tcpNoDelay.booleanValue()); + if (soTrafficClass != null) + socket.setTrafficClass(soTrafficClass.intValue()); } public boolean getDirectBuffer() { @@ -184,55 +210,55 @@ public class SocketProperties { } public boolean getOoBInline() { - return ooBInline; + return ooBInline.booleanValue(); } public int getPerformanceBandwidth() { - return performanceBandwidth; + return performanceBandwidth.intValue(); } public int getPerformanceConnectionTime() { - return performanceConnectionTime; + return performanceConnectionTime.intValue(); } public int getPerformanceLatency() { - return performanceLatency; + return performanceLatency.intValue(); } public int getRxBufSize() { - return rxBufSize; + return rxBufSize.intValue(); } public boolean getSoKeepAlive() { - return soKeepAlive; + return soKeepAlive.booleanValue(); } public boolean getSoLingerOn() { - return soLingerOn; + return soLingerOn.booleanValue(); } public int getSoLingerTime() { - return soLingerTime; + return soLingerTime.intValue(); } public boolean getSoReuseAddress() { - return soReuseAddress; + return soReuseAddress.booleanValue(); } public int getSoTimeout() { - return soTimeout; + return soTimeout.intValue(); } public int getSoTrafficClass() { - return soTrafficClass; + return soTrafficClass.intValue(); } public boolean getTcpNoDelay() { - return tcpNoDelay; + return tcpNoDelay.booleanValue(); } public int getTxBufSize() { - return txBufSize; + return txBufSize.intValue(); } public int getBufferPool() { @@ -251,10 +277,6 @@ public class SocketProperties { return keyCache; } - public Socket getProperties() { - return properties; - } - public int getAppReadBufSize() { return appReadBufSize; } @@ -276,51 +298,52 @@ public class SocketProperties { } public void setPerformanceConnectionTime(int performanceConnectionTime) { - this.performanceConnectionTime = performanceConnectionTime; + this.performanceConnectionTime = + Integer.valueOf(performanceConnectionTime); } public void setTxBufSize(int txBufSize) { - this.txBufSize = txBufSize; + this.txBufSize = Integer.valueOf(txBufSize); } public void setTcpNoDelay(boolean tcpNoDelay) { - this.tcpNoDelay = tcpNoDelay; + this.tcpNoDelay = Boolean.valueOf(tcpNoDelay); } public void setSoTrafficClass(int soTrafficClass) { - this.soTrafficClass = soTrafficClass; + this.soTrafficClass = Integer.valueOf(soTrafficClass); } public void setSoTimeout(int soTimeout) { - this.soTimeout = soTimeout; + this.soTimeout = Integer.valueOf(soTimeout); } public void setSoReuseAddress(boolean soReuseAddress) { - this.soReuseAddress = soReuseAddress; + this.soReuseAddress = Boolean.valueOf(soReuseAddress); } public void setSoLingerTime(int soLingerTime) { - this.soLingerTime = soLingerTime; + this.soLingerTime = Integer.valueOf(soLingerTime); } public void setSoKeepAlive(boolean soKeepAlive) { - this.soKeepAlive = soKeepAlive; + this.soKeepAlive = Boolean.valueOf(soKeepAlive); } public void setRxBufSize(int rxBufSize) { - this.rxBufSize = rxBufSize; + this.rxBufSize = Integer.valueOf(rxBufSize); } public void setPerformanceLatency(int performanceLatency) { - this.performanceLatency = performanceLatency; + this.performanceLatency = Integer.valueOf(performanceLatency); } public void setPerformanceBandwidth(int performanceBandwidth) { - this.performanceBandwidth = performanceBandwidth; + this.performanceBandwidth = Integer.valueOf(performanceBandwidth); } public void setOoBInline(boolean ooBInline) { - this.ooBInline = ooBInline; + this.ooBInline = Boolean.valueOf(ooBInline); } public void setDirectBuffer(boolean directBuffer) { @@ -328,7 +351,7 @@ public class SocketProperties { } public void setSoLingerOn(boolean soLingerOn) { - this.soLingerOn = soLingerOn; + this.soLingerOn = Boolean.valueOf(soLingerOn); } public void setBufferPool(int bufferPool) { diff --git a/webapps/docs/config/http.xml b/webapps/docs/config/http.xml index 6539e15f6..981d93fe1 100644 --- a/webapps/docs/config/http.xml +++ b/webapps/docs/config/http.xml @@ -386,45 +386,64 @@ -

(int)The socket receive buffer (SO_RCVBUF) size in bytes. Default value is 25188

+

(int)The socket receive buffer (SO_RCVBUF) size in bytes. JVM default + used if not set.

-

(int)The socket send buffer (SO_SNDBUF) size in bytes. Default value is 43800

+

(int)The socket send buffer (SO_SNDBUF) size in bytes. JVM default + used if not set.

-

(bool)same as the standard setting tcpNoDelay. Default value is false

+

(bool)same as the standard setting tcpNoDelay. JVM + default used if not set.

-

(bool)Boolean value for the socket's keep alive setting (SO_KEEPALIVE). Default is false.

+

(bool)Boolean value for the socket's keep alive setting + (SO_KEEPALIVE). JVM default used if not set.

-

(bool)Boolean value for the socket OOBINLINE setting. Default value is true

+

(bool)Boolean value for the socket OOBINLINE setting. JVM default + used if not set.

-

(bool)Boolean value for the sockets reuse address option (SO_REUSEADDR). Default value is true

+

(bool)Boolean value for the sockets reuse address option + (SO_REUSEADDR). JVM default used if not set.

-

(bool)Boolean value for the sockets so linger option (SO_LINGER). Default value is true. - This option is paired with the soLingerTime value.

+

(bool)Boolean value for the sockets so linger option (SO_LINGER). + Both this attribute and soLingerTime must be set else the + JVM defaults will be used for both.

-

(bool)Value in seconds for the sockets so linger option (SO_LINGER). Default value is 25 seconds. - This option is paired with the soLinger value.

+

(bool)Value in seconds for the sockets so linger option (SO_LINGER). + Both this attribute and soLingerOn must be set else the + JVM defaults will be used for both.

-

(int)Value in milliseconds for the sockets read timeout (SO_TIMEOUT). Default value is 5000 milliseconds.

+

(int)Value in milliseconds for the sockets read timeout (SO_TIMEOUT). + JVM default used if not set.

-

(byte)Value between 0 and 255 for the traffic class on the socket, 0x04 | 0x08 | 0x010

+

(byte)Value between 0 and 255 for the + traffic class on the socket. JVM default used if not set.

-

(int)The first value for the performance settings. Default is 1, see Socket Performance Options

+

(int)The first value for the performance settings. See + Socket Performance Options + All three performance attributes must be set else the JVM defaults will + be used for all three.

-

(int)The second value for the performance settings. Default is 0, see Socket Performance Options

+

(int)The second value for the performance settings. See + Socket Performance Options + All three performance attributes must be set else the JVM defaults will + be used for all three.

-

(int)The third value for the performance settings. Default is 1, see Socket Performance Options

+

(int)The third value for the performance settings. See + Socket Performance Options + All three performance attributes must be set else the JVM defaults will + be used for all three.

-- 2.11.0