Search in sources :

Example 1 with SslFuture

use of com.generallycloud.baseio.protocol.SslFuture in project baseio by generallycloud.

the class SslChannelByteBufReader method accept.

@Override
public void accept(SocketChannel channel, ByteBuf buffer) throws Exception {
    for (; ; ) {
        if (!buffer.hasRemaining()) {
            return;
        }
        SslFuture future = channel.getSslReadFuture();
        boolean setFutureNull = true;
        if (future == null) {
            future = this.temporary.reset();
            setFutureNull = false;
        }
        try {
            if (!future.read(channel, buffer)) {
                if (!setFutureNull) {
                    if (future == this.temporary) {
                        future = future.copy(channel);
                    }
                    channel.setSslReadFuture(future);
                }
                return;
            }
        } catch (Throwable e) {
            ReleaseUtil.release(future);
            channel.setSslReadFuture(null);
            if (e instanceof IOException) {
                throw (IOException) e;
            }
            throw new IOException("exception occurred when do decode ssl," + e.getMessage(), e);
        }
        if (setFutureNull) {
            channel.setSslReadFuture(null);
        }
        SslHandler sslHandler = channel.getSslHandler();
        ByteBuf product;
        try {
            product = sslHandler.unwrap(channel, future.getByteBuf());
        } finally {
            ReleaseUtil.release(future);
        }
        if (product == null) {
            continue;
        }
        nextAccept(channel, product);
    }
}
Also used : IOException(java.io.IOException) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf) SslFuture(com.generallycloud.baseio.protocol.SslFuture) SslHandler(com.generallycloud.baseio.component.ssl.SslHandler)

Aggregations

ByteBuf (com.generallycloud.baseio.buffer.ByteBuf)1 SslHandler (com.generallycloud.baseio.component.ssl.SslHandler)1 SslFuture (com.generallycloud.baseio.protocol.SslFuture)1 IOException (java.io.IOException)1