use of com.generallycloud.baseio.buffer.ByteBuf in project baseio by generallycloud.
the class Http2WindowUpdateFrameImpl method read.
@Override
public boolean read(SocketChannel channel, ByteBuf buffer) throws IOException {
if (!isComplete) {
ByteBuf buf = this.buf;
buf.read(buffer);
if (buf.hasRemaining()) {
return false;
}
isComplete = true;
doComplete((SocketChannel) channel, buf.flip());
}
return true;
}
use of com.generallycloud.baseio.buffer.ByteBuf in project baseio by generallycloud.
the class ParamedProtobaseProtocolDecoder method decode.
@Override
public ChannelFuture decode(SocketChannel channel, ByteBuf buffer) throws IOException {
ByteBufAllocator allocator = channel.getByteBufAllocator();
ByteBuf buf = allocator.allocate(2);
return new ParamedProtobaseFutureImpl(channel, buf);
}
use of com.generallycloud.baseio.buffer.ByteBuf in project baseio by generallycloud.
the class SslHandler method wrap.
public ByteBuf wrap(SocketChannel channel, ByteBuf src) throws IOException {
SSLEngine engine = channel.getSSLEngine();
ByteBuf dst = getTempDst(engine);
ByteBuf out = null;
try {
for (; ; ) {
dst.clear();
SSLEngineResult result = engine.wrap(src.nioBuffer(), dst.nioBuffer());
Status status = result.getStatus();
HandshakeStatus handshakeStatus = result.getHandshakeStatus();
synchByteBuf(result, src, dst);
if (status == Status.CLOSED) {
return gc(channel, dst.flip());
}
if (handshakeStatus != HandshakeStatus.NOT_HANDSHAKING) {
if (handshakeStatus == HandshakeStatus.NEED_UNWRAP) {
if (out != null) {
out.read(dst.flip());
return out.flip();
}
return gc(channel, dst.flip());
} else if (handshakeStatus == HandshakeStatus.NEED_WRAP) {
if (out == null) {
out = allocate(channel, 256);
}
out.read(dst.flip());
continue;
} else if (handshakeStatus == HandshakeStatus.FINISHED) {
channel.finishHandshake(null);
out.read(dst.flip());
return out.flip();
} else if (handshakeStatus == HandshakeStatus.NEED_TASK) {
runDelegatedTasks(engine);
continue;
}
}
if (src.hasRemaining()) {
if (out == null) {
int outLength = ((src.limit() / src.position()) + 1) * (dst.position() - src.position()) + src.limit();
out = allocate(channel, outLength);
}
out.read(dst.flip());
continue;
}
if (out != null) {
out.read(dst.flip());
return out.flip();
}
return gc(channel, dst.flip());
}
} catch (Throwable e) {
ReleaseUtil.release(out);
if (e instanceof IOException) {
throw (IOException) e;
}
throw new IOException(e);
}
}
use of com.generallycloud.baseio.buffer.ByteBuf in project baseio by generallycloud.
the class SslHandler method unwrap.
public ByteBuf unwrap(SocketChannel channel, ByteBuf src) throws IOException {
SSLEngine sslEngine = channel.getSSLEngine();
ByteBuf dst = getTempDst(sslEngine);
for (; ; ) {
dst.clear();
SSLEngineResult result = sslEngine.unwrap(src.nioBuffer(), dst.nioBuffer());
HandshakeStatus handshakeStatus = result.getHandshakeStatus();
synchByteBuf(result, src, dst);
if (handshakeStatus != HandshakeStatus.NOT_HANDSHAKING) {
if (handshakeStatus == HandshakeStatus.NEED_WRAP) {
channel.doFlush(forgeFuture.duplicate());
return null;
} else if (handshakeStatus == HandshakeStatus.NEED_TASK) {
runDelegatedTasks(sslEngine);
continue;
} else if (handshakeStatus == HandshakeStatus.FINISHED) {
channel.finishHandshake(null);
return null;
} else if (handshakeStatus == HandshakeStatus.NEED_UNWRAP) {
return null;
}
}
return dst.flip();
}
}
use of com.generallycloud.baseio.buffer.ByteBuf in project baseio by generallycloud.
the class SocketSelectorEventLoop method accept.
private void accept(NioSocketChannel channel) {
try {
ByteBuf buf = this.buf;
buf.clear();
buf.nioBuffer();
int length = channel.read(buf);
if (length < 1) {
if (length == -1) {
CloseUtil.close(channel);
}
return;
}
channel.active();
byteBufReader.accept(channel, buf.flip());
} catch (Throwable e) {
if (e instanceof SSLHandshakeException) {
// failed connect , the session should be null
getSelector().finishConnect(null, e);
}
closeSocketChannel(channel, e);
}
}
Aggregations