This commit is contained in:
@@ -27,10 +27,13 @@ public final class PrepareRunner implements Runnable {
|
||||
|
||||
private ByteBuffer data;
|
||||
|
||||
public PrepareRunner(Context context, AsyncConnection channel, ByteBuffer data) {
|
||||
private Response response;
|
||||
|
||||
public PrepareRunner(Context context, AsyncConnection channel, ByteBuffer data, Response response) {
|
||||
this.context = context;
|
||||
this.channel = channel;
|
||||
this.data = data;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +41,7 @@ public final class PrepareRunner implements Runnable {
|
||||
final PrepareServlet prepare = context.prepare;
|
||||
final ObjectPool<? extends Response> responsePool = context.responsePool;
|
||||
if (data != null) { //BIO模式的UDP连接创建AsyncConnection时已经获取到ByteBuffer数据了
|
||||
final Response response = responsePool.get();
|
||||
if (response == null) response = responsePool.get();
|
||||
response.init(channel);
|
||||
try {
|
||||
prepare.prepare(data, response.request, response);
|
||||
@@ -48,7 +51,7 @@ public final class PrepareRunner implements Runnable {
|
||||
}
|
||||
return;
|
||||
}
|
||||
final Response response = responsePool.get();
|
||||
if (response == null) response = responsePool.get();
|
||||
final ByteBuffer buffer = response.request.pollReadBuffer();
|
||||
try {
|
||||
channel.read(buffer, null, new CompletionHandler<Integer, Void>() {
|
||||
|
||||
@@ -123,7 +123,7 @@ public abstract class ProtocolServer {
|
||||
SocketAddress address = serchannel.receive(buffer);
|
||||
buffer.flip();
|
||||
AsyncConnection conn = AsyncConnection.create(serchannel, address, false, readTimeoutSecond, writeTimeoutSecond);
|
||||
context.runAsync(new PrepareRunner(context, conn, buffer));
|
||||
context.runAsync(new PrepareRunner(context, conn, buffer, null));
|
||||
} catch (Exception e) {
|
||||
context.offerBuffer(buffer);
|
||||
}
|
||||
@@ -217,7 +217,7 @@ public abstract class ProtocolServer {
|
||||
AsyncConnection conn = AsyncConnection.create(channel, null, context);
|
||||
conn.livingCounter = livingCounter;
|
||||
conn.closedCounter = closedCounter;
|
||||
context.runAsync(new PrepareRunner(context, conn, null));
|
||||
context.runAsync(new PrepareRunner(context, conn, null, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -184,7 +184,9 @@ public abstract class Response<C extends Context, R extends Request<C>> {
|
||||
request.recycle();
|
||||
if (channel != null) {
|
||||
if (keepAlive) {
|
||||
this.context.runAsync(new PrepareRunner(context, channel, null));
|
||||
this.inited = false;
|
||||
this.context.runAsync(new PrepareRunner(context, removeChannel(), null, this));
|
||||
return false;
|
||||
} else {
|
||||
try {
|
||||
if (channel.isOpen()) channel.close();
|
||||
|
||||
Reference in New Issue
Block a user