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