You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/04/09 20:58:39 UTC
svn commit: r1672452 - in /tomcat/trunk/java/org/apache/tomcat/util/net:
NioEndpoint.java SecureNioChannel.java SocketBufferHandler.java
Author: markt
Date: Thu Apr 9 18:58:39 2015
New Revision: 1672452
URL: http://svn.apache.org/r1672452
Log:
More SNI refactoring. Should be ready to start peeking at the input stream now.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java
tomcat/trunk/java/org/apache/tomcat/util/net/SocketBufferHandler.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1672452&r1=1672451&r2=1672452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu Apr 9 18:58:39 2015
@@ -456,32 +456,19 @@ public class NioEndpoint extends Abstrac
socketProperties.setProperties(sock);
NioChannel channel = nioChannels.pop();
- if ( channel == null ) {
- // SSL setup
+ if (channel == null) {
+ SocketBufferHandler bufhandler = new SocketBufferHandler(
+ socketProperties.getAppReadBufSize(),
+ socketProperties.getAppWriteBufSize(),
+ socketProperties.getDirectBuffer());
if (isSSLEnabled()) {
- SSLEngine engine = createSSLEngine();
- int appbufsize = engine.getSession().getApplicationBufferSize();
- SocketBufferHandler bufhandler = new SocketBufferHandler(
- Math.max(appbufsize,socketProperties.getAppReadBufSize()),
- Math.max(appbufsize,socketProperties.getAppWriteBufSize()),
- socketProperties.getDirectBuffer());
- channel = new SecureNioChannel(socket, engine, bufhandler, selectorPool, this);
+ channel = new SecureNioChannel(socket, bufhandler, selectorPool, this);
} else {
- // normal tcp setup
- SocketBufferHandler bufhandler = new SocketBufferHandler(
- socketProperties.getAppReadBufSize(),
- socketProperties.getAppWriteBufSize(),
- socketProperties.getDirectBuffer());
channel = new NioChannel(socket, bufhandler);
}
} else {
channel.setIOChannel(socket);
- if ( channel instanceof SecureNioChannel ) {
- SSLEngine engine = createSSLEngine();
- ((SecureNioChannel)channel).reset(engine);
- } else {
- channel.reset();
- }
+ channel.reset();
}
getPoller0().register(channel);
} catch (Throwable t) {
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java?rev=1672452&r1=1672451&r2=1672452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SecureNioChannel.java Thu Apr 9 18:58:39 2015
@@ -54,24 +54,19 @@ public class SecureNioChannel extends Ni
protected NioSelectorPool pool;
private final NioEndpoint endpoint;
- public SecureNioChannel(SocketChannel channel, SSLEngine engine, SocketBufferHandler bufHandler,
+ public SecureNioChannel(SocketChannel channel, SocketBufferHandler bufHandler,
NioSelectorPool pool, NioEndpoint endpoint) {
- super(channel,bufHandler);
- this.sslEngine = engine;
+ super(channel, bufHandler);
// selector pool for blocking operations
this.pool = pool;
this.endpoint = endpoint;
}
- public void reset(SSLEngine engine) throws IOException {
- this.sslEngine = engine;
- reset();
- }
-
@Override
public void reset() throws IOException {
super.reset();
+ sslEngine = null;
sniComplete = false;
handshakeComplete = false;
closed = false;
@@ -221,6 +216,12 @@ public class SecureNioChannel extends Ni
// via SNI (if any) goes here.
SocketProperties sp = endpoint.getSocketProperties();
+ sslEngine = endpoint.createSSLEngine();
+
+ // Ensure the application buffers (which have to be created earlier) are
+ // big enough.
+ bufHandler.expand(sslEngine.getSession().getApplicationBufferSize());
+
// Create/expand network buffers.
// In/Out are always created in a pair with identical settings so only
// need to test one to determine what needs to be done for both.
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketBufferHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketBufferHandler.java?rev=1672452&r1=1672451&r2=1672452&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketBufferHandler.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketBufferHandler.java Thu Apr 9 18:58:39 2015
@@ -21,10 +21,10 @@ import java.nio.ByteBuffer;
public class SocketBufferHandler {
private volatile boolean readBufferConfiguredForWrite = true;
- private final ByteBuffer readBuffer;
+ private volatile ByteBuffer readBuffer;
private volatile boolean writeBufferConfiguredForWrite = true;
- private final ByteBuffer writeBuffer;
+ private volatile ByteBuffer writeBuffer;
public SocketBufferHandler(int readBufferSize, int writeBufferSize,
@@ -146,4 +146,34 @@ public class SocketBufferHandler {
writeBuffer.clear();
writeBufferConfiguredForWrite = true;
}
+
+
+ public void expand(int newSize) {
+ if (readBuffer.capacity() < newSize) {
+ ByteBuffer newReadBuffer;
+ if (readBuffer.isDirect()) {
+ newReadBuffer = ByteBuffer.allocateDirect(newSize);
+ } else {
+ newReadBuffer = ByteBuffer.allocate(newSize);
+ }
+ configureReadBufferForRead();
+ newReadBuffer.put(readBuffer);
+ newReadBuffer.flip();
+ readBuffer = newReadBuffer;
+
+ }
+
+ if (writeBuffer.capacity() < newSize) {
+ ByteBuffer newWriteBuffer;
+ if (writeBuffer.isDirect()) {
+ newWriteBuffer = ByteBuffer.allocateDirect(newSize);
+ } else {
+ newWriteBuffer = ByteBuffer.allocate(newSize);
+ }
+ configureWriteBufferForRead();
+ newWriteBuffer.put(writeBuffer);
+ newWriteBuffer.flip();
+ writeBuffer = newWriteBuffer;
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org