ProtocolCodec.readRegister 优化

This commit is contained in:
redkale
2024-10-05 22:19:52 +08:00
parent 154fd08183
commit 7bab2742a5
5 changed files with 9 additions and 8 deletions

View File

@@ -114,7 +114,8 @@ class ProtocolCodec implements CompletionHandler<Integer, ByteBuffer> {
return;
}
try {
channel.readRegisterInIOThread(this);
//channel.readRegisterInIOThread(this);
channel.readRegister(this);
} catch (Exception te) {
channel.dispose(); // response.init(channel); 在调用之前异常
if (context.logger.isLoggable(Level.FINEST)) {

View File

@@ -37,7 +37,7 @@ public abstract class Request<C extends Context> {
// 请求包是否完成读取完毕用于ProtocolCodec继续读的判断条件
// 需要在readHeader方法中设置
protected boolean completed;
protected boolean readCompleted;
protected int pipelineIndex;
@@ -109,7 +109,7 @@ public abstract class Request<C extends Context> {
pipelineIndex = 0;
pipelineCount = 0;
pipelineCompleted = false;
completed = false;
readCompleted = false;
keepAlive = false;
attributes.clear();
annotations = null;

View File

@@ -348,7 +348,7 @@ public abstract class Response<C extends Context, R extends Request<C>> {
AsyncConnection conn = removeChannel();
if (conn != null && conn.protocolCodec != null) {
this.responseConsumer.accept(this);
if (!request.completed) {
if (!request.readCompleted) {
conn.readRegister(conn.protocolCodec);
this.readRegistered = true;
}

View File

@@ -400,8 +400,8 @@ public class HttpRequest extends Request<HttpContext> {
// 文件上传必须设置keepAlive为false因为文件过大时用户不一定会skip掉多余的数据
this.keepAlive = false;
}
// completed=true时ProtocolCodec会继续读下一个request
this.completed = !this.boundary && !maybews;
// readCompleted=true时ProtocolCodec会继续读下一个request
this.readCompleted = !this.boundary && !maybews;
this.bodyBytes.clear();
this.readState = READ_STATE_BODY;
}

View File

@@ -125,8 +125,8 @@ public class SncpRequest extends Request<SncpContext> {
return -1;
}
this.traceid = this.header.getTraceid();
// completed=true时ProtocolCodec会继续读下一个request
this.completed = true;
// readCompleted=true时ProtocolCodec会继续读下一个request
this.readCompleted = true;
this.readState = READ_STATE_BODY;
}
// ---------------------body----------------------------------