Skip to content

Commit

Permalink
Single shared buffer pool for SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Dec 13, 2013
1 parent 9197384 commit 266d911
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions api/src/main/java/org/xnio/ssl/JsseXnioSsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
* @author <a href="mailto:frainone@redhat.com">Flavia Rainone</a>
*/
public final class JsseXnioSsl extends XnioSsl {
private final Pool<ByteBuffer> socketBufferPool;
private final Pool<ByteBuffer> applicationBufferPool;
private static final Pool<ByteBuffer> bufferPool = new ByteBufferSlicePool(BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR, 17 * 1024, 17 * 1024 * 128);
private final SSLContext sslContext;

/**
Expand All @@ -89,13 +88,6 @@ public JsseXnioSsl(final Xnio xnio, final OptionMap optionMap) throws NoSuchProv
*/
public JsseXnioSsl(final Xnio xnio, final OptionMap optionMap, final SSLContext sslContext) {
super(xnio, sslContext, optionMap);
// todo - find out better default values
final int appBufSize = optionMap.get(Options.SSL_APPLICATION_BUFFER_SIZE, 17000);
final int pktBufSize = optionMap.get(Options.SSL_PACKET_BUFFER_SIZE, 17000);
final int appBufRegionSize = optionMap.get(Options.SSL_APPLICATION_BUFFER_REGION_SIZE, appBufSize * 16);
final int pktBufRegionSize = optionMap.get(Options.SSL_PACKET_BUFFER_REGION_SIZE, pktBufSize * 16);
socketBufferPool = new ByteBufferSlicePool(optionMap.get(Options.USE_DIRECT_BUFFERS, false) ? BufferAllocator.DIRECT_BYTE_BUFFER_ALLOCATOR : BufferAllocator.BYTE_BUFFER_ALLOCATOR, pktBufSize, pktBufRegionSize);
applicationBufferPool = new ByteBufferSlicePool(BufferAllocator.BYTE_BUFFER_ALLOCATOR, appBufSize, appBufRegionSize);
this.sslContext = sslContext;
}

Expand Down Expand Up @@ -156,7 +148,7 @@ public IoFuture<SslConnection> openSslConnection(final XnioWorker worker, final
final FutureResult<SslConnection> futureResult = new FutureResult<SslConnection>(worker);
final IoFuture<StreamConnection> connection = worker.openStreamConnection(bindAddress, destination, new ChannelListener<StreamConnection>() {
public void handleEvent(final StreamConnection connection) {
final SslConnection wrappedConnection = new JsseSslStreamConnection(connection, JsseSslUtils.createSSLEngine(sslContext, optionMap, destination), socketBufferPool, applicationBufferPool, optionMap.get(Options.SSL_STARTTLS, false));
final SslConnection wrappedConnection = new JsseSslStreamConnection(connection, JsseSslUtils.createSSLEngine(sslContext, optionMap, destination), bufferPool, bufferPool, optionMap.get(Options.SSL_STARTTLS, false));
if (! futureResult.setResult(wrappedConnection)) {
IoUtils.safeClose(connection);
} else {
Expand Down Expand Up @@ -264,7 +256,7 @@ public <T> T setOption(final Option<T> option, final T value) throws IllegalArgu
}

public AcceptingChannel<SslConnection> createSslConnectionServer(final XnioWorker worker, final InetSocketAddress bindAddress, final ChannelListener<? super AcceptingChannel<SslConnection>> acceptListener, final OptionMap optionMap) throws IOException {
final JsseAcceptingSslStreamConnection server = new JsseAcceptingSslStreamConnection(sslContext, worker.createStreamConnectionServer(bindAddress, null, optionMap), optionMap, socketBufferPool, applicationBufferPool, optionMap.get(Options.SSL_STARTTLS, false));
final JsseAcceptingSslStreamConnection server = new JsseAcceptingSslStreamConnection(sslContext, worker.createStreamConnectionServer(bindAddress, null, optionMap), optionMap, bufferPool, bufferPool, optionMap.get(Options.SSL_STARTTLS, false));
if (acceptListener != null) server.getAcceptSetter().set(acceptListener);
return server;
}
Expand Down

0 comments on commit 266d911

Please sign in to comment.