package org.xnio.ssl;
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import org.xnio.IoUtils;
import org.xnio.OptionMap;
import org.xnio.Pool;
import org.xnio.StreamConnection;
import org.xnio.channels.AcceptingChannel;
final class JsseAcceptingSslStreamConnection extends AbstractAcceptingSslChannel<SslConnection, StreamConnection> {
JsseAcceptingSslStreamConnection(final SSLContext sslContext, final AcceptingChannel<? extends StreamConnection> tcpServer, final OptionMap optionMap, final Pool<ByteBuffer> socketBufferPool, final Pool<ByteBuffer> applicationBufferPool, final boolean startTls) {
super(sslContext, tcpServer, optionMap, socketBufferPool, applicationBufferPool, startTls);
}
@Override
public SslConnection accept(StreamConnection tcpConnection, SSLEngine engine) throws IOException {
if (! JsseXnioSsl.NEW_IMPL) {
return new JsseSslStreamConnection(tcpConnection, engine, socketBufferPool, applicationBufferPool, startTls);
}
JsseSslConnection connection = new JsseSslConnection(tcpConnection, engine, socketBufferPool, applicationBufferPool);
if (!startTls) {
try {
connection.startHandshake();
} catch (IOException e) {
IoUtils.safeClose(connection);
throw e;
}
}
return connection;
}
}