Search in sources :

Example 1 with SslHandler

use of com.generallycloud.baseio.component.ssl.SslHandler in project baseio by generallycloud.

the class AbstractChannelFuture method wrapSSL.

private void wrapSSL(SocketChannel channel) throws IOException {
    // FIXME 部分情况下可以不在业务线程做wrapssl
    ByteBuf old = this.buf;
    SslHandler handler = channel.getSslHandler();
    try {
        this.buf = handler.wrap(channel, old);
        this.buf.nioBuffer();
    } finally {
        ReleaseUtil.release(old);
    }
}
Also used : EmptyByteBuf(com.generallycloud.baseio.buffer.EmptyByteBuf) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf) SslHandler(com.generallycloud.baseio.component.ssl.SslHandler)

Example 2 with SslHandler

use of com.generallycloud.baseio.component.ssl.SslHandler 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)2 SslHandler (com.generallycloud.baseio.component.ssl.SslHandler)2 EmptyByteBuf (com.generallycloud.baseio.buffer.EmptyByteBuf)1 SslFuture (com.generallycloud.baseio.protocol.SslFuture)1 IOException (java.io.IOException)1