This commit is contained in:
Redkale
2017-03-24 11:28:01 +08:00
parent 0366aef672
commit eca138b671
2 changed files with 11 additions and 1 deletions

View File

@@ -162,13 +162,14 @@ public abstract class Response<C extends Context, R extends Request<C>> {
}
public void finish(boolean kill) {
if (!this.inited) return; //重复关闭
if (!this.inited) return; //避免重复关闭
//System.println("耗时: " + (System.currentTimeMillis() - request.createtime));
if (kill) refuseAlive();
this.context.responsePool.offer(this);
}
public void finish(final byte[] bs) {
if (!this.inited) return; //避免重复关闭
if (this.context.bufferCapacity == bs.length) {
ByteBuffer buffer = this.context.pollBuffer();
buffer.put(bs);
@@ -180,19 +181,23 @@ public abstract class Response<C extends Context, R extends Request<C>> {
}
public void finish(ByteBuffer buffer) {
if (!this.inited) return; //避免重复关闭
this.channel.write(buffer, buffer, finishHandler);
}
public void finish(boolean kill, ByteBuffer buffer) {
if (!this.inited) return; //避免重复关闭
if (kill) refuseAlive();
this.channel.write(buffer, buffer, finishHandler);
}
public void finish(ByteBuffer... buffers) {
if (!this.inited) return; //避免重复关闭
this.channel.write(buffers, buffers, finishHandler2);
}
public void finish(boolean kill, ByteBuffer... buffers) {
if (!this.inited) return; //避免重复关闭
if (kill) refuseAlive();
this.channel.write(buffers, buffers, finishHandler2);
}

View File

@@ -317,6 +317,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
* @param obj 输出内容
*/
public void finish(String obj) {
if (isClosed()) return;
if (this.recycleListener != null) this.output = obj;
if (obj == null || obj.isEmpty()) {
final ByteBuffer headbuf = createHeader();
@@ -358,6 +359,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
* @param message 输出内容
*/
public void finish(int status, String message) {
if (isClosed()) return;
this.status = status;
if (status != 200) super.refuseAlive();
finish(message);
@@ -384,6 +386,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
*/
@Override
public void finish(final byte[] bs) {
if (isClosed()) return; //避免重复关闭
if (this.context.getBufferCapacity() == bs.length) {
ByteBuffer buffer = this.context.pollBuffer();
buffer.put(bs);
@@ -412,6 +415,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
*/
@Override
public void finish(boolean kill, ByteBuffer buffer) {
if (isClosed()) return; //避免重复关闭
if (!this.headsended) {
this.contentLength = buffer == null ? 0 : buffer.remaining();
ByteBuffer headbuf = createHeader();
@@ -444,6 +448,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
*/
@Override
public void finish(boolean kill, ByteBuffer... buffers) {
if (isClosed()) return; //避免重复关闭
if (bufferHandler != null) {
ByteBuffer[] bufs = bufferHandler.execute(this, buffers);
if (bufs != null) buffers = bufs;