This commit is contained in:
@@ -162,13 +162,14 @@ public abstract class Response<C extends Context, R extends Request<C>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void finish(boolean kill) {
|
public void finish(boolean kill) {
|
||||||
if (!this.inited) return; //重复关闭
|
if (!this.inited) return; //避免重复关闭
|
||||||
//System.println("耗时: " + (System.currentTimeMillis() - request.createtime));
|
//System.println("耗时: " + (System.currentTimeMillis() - request.createtime));
|
||||||
if (kill) refuseAlive();
|
if (kill) refuseAlive();
|
||||||
this.context.responsePool.offer(this);
|
this.context.responsePool.offer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(final byte[] bs) {
|
public void finish(final byte[] bs) {
|
||||||
|
if (!this.inited) return; //避免重复关闭
|
||||||
if (this.context.bufferCapacity == bs.length) {
|
if (this.context.bufferCapacity == bs.length) {
|
||||||
ByteBuffer buffer = this.context.pollBuffer();
|
ByteBuffer buffer = this.context.pollBuffer();
|
||||||
buffer.put(bs);
|
buffer.put(bs);
|
||||||
@@ -180,19 +181,23 @@ public abstract class Response<C extends Context, R extends Request<C>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void finish(ByteBuffer buffer) {
|
public void finish(ByteBuffer buffer) {
|
||||||
|
if (!this.inited) return; //避免重复关闭
|
||||||
this.channel.write(buffer, buffer, finishHandler);
|
this.channel.write(buffer, buffer, finishHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(boolean kill, ByteBuffer buffer) {
|
public void finish(boolean kill, ByteBuffer buffer) {
|
||||||
|
if (!this.inited) return; //避免重复关闭
|
||||||
if (kill) refuseAlive();
|
if (kill) refuseAlive();
|
||||||
this.channel.write(buffer, buffer, finishHandler);
|
this.channel.write(buffer, buffer, finishHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(ByteBuffer... buffers) {
|
public void finish(ByteBuffer... buffers) {
|
||||||
|
if (!this.inited) return; //避免重复关闭
|
||||||
this.channel.write(buffers, buffers, finishHandler2);
|
this.channel.write(buffers, buffers, finishHandler2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finish(boolean kill, ByteBuffer... buffers) {
|
public void finish(boolean kill, ByteBuffer... buffers) {
|
||||||
|
if (!this.inited) return; //避免重复关闭
|
||||||
if (kill) refuseAlive();
|
if (kill) refuseAlive();
|
||||||
this.channel.write(buffers, buffers, finishHandler2);
|
this.channel.write(buffers, buffers, finishHandler2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -317,6 +317,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
* @param obj 输出内容
|
* @param obj 输出内容
|
||||||
*/
|
*/
|
||||||
public void finish(String obj) {
|
public void finish(String obj) {
|
||||||
|
if (isClosed()) return;
|
||||||
if (this.recycleListener != null) this.output = obj;
|
if (this.recycleListener != null) this.output = obj;
|
||||||
if (obj == null || obj.isEmpty()) {
|
if (obj == null || obj.isEmpty()) {
|
||||||
final ByteBuffer headbuf = createHeader();
|
final ByteBuffer headbuf = createHeader();
|
||||||
@@ -358,6 +359,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
* @param message 输出内容
|
* @param message 输出内容
|
||||||
*/
|
*/
|
||||||
public void finish(int status, String message) {
|
public void finish(int status, String message) {
|
||||||
|
if (isClosed()) return;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
if (status != 200) super.refuseAlive();
|
if (status != 200) super.refuseAlive();
|
||||||
finish(message);
|
finish(message);
|
||||||
@@ -384,6 +386,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void finish(final byte[] bs) {
|
public void finish(final byte[] bs) {
|
||||||
|
if (isClosed()) return; //避免重复关闭
|
||||||
if (this.context.getBufferCapacity() == bs.length) {
|
if (this.context.getBufferCapacity() == bs.length) {
|
||||||
ByteBuffer buffer = this.context.pollBuffer();
|
ByteBuffer buffer = this.context.pollBuffer();
|
||||||
buffer.put(bs);
|
buffer.put(bs);
|
||||||
@@ -412,6 +415,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void finish(boolean kill, ByteBuffer buffer) {
|
public void finish(boolean kill, ByteBuffer buffer) {
|
||||||
|
if (isClosed()) return; //避免重复关闭
|
||||||
if (!this.headsended) {
|
if (!this.headsended) {
|
||||||
this.contentLength = buffer == null ? 0 : buffer.remaining();
|
this.contentLength = buffer == null ? 0 : buffer.remaining();
|
||||||
ByteBuffer headbuf = createHeader();
|
ByteBuffer headbuf = createHeader();
|
||||||
@@ -444,6 +448,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void finish(boolean kill, ByteBuffer... buffers) {
|
public void finish(boolean kill, ByteBuffer... buffers) {
|
||||||
|
if (isClosed()) return; //避免重复关闭
|
||||||
if (bufferHandler != null) {
|
if (bufferHandler != null) {
|
||||||
ByteBuffer[] bufs = bufferHandler.execute(this, buffers);
|
ByteBuffer[] bufs = bufferHandler.execute(this, buffers);
|
||||||
if (bufs != null) buffers = bufs;
|
if (bufs != null) buffers = bufs;
|
||||||
|
|||||||
Reference in New Issue
Block a user