Skip to content

Commit

Permalink
415314 Jetty should not commit response on output if < Response.setBu…
Browse files Browse the repository at this point in the history
…fferSize() bytes are written
  • Loading branch information
janbartel committed Aug 19, 2013
1 parent c0402de commit ad8db51
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -57,6 +57,7 @@ public class HttpOutput extends ServletOutputStream implements Runnable
private long _written;
private ByteBuffer _aggregate;
private int _bufferSize;
private int _commitSize;
private WriteListener _writeListener;
private volatile Throwable _onError;

Expand All @@ -79,6 +80,7 @@ public HttpOutput(HttpChannel<?> channel)
{
_channel = channel;
_bufferSize = _channel.getHttpConfiguration().getOutputBufferSize();
_commitSize=_bufferSize/4;
}

public boolean isWritten()
Expand Down Expand Up @@ -231,7 +233,7 @@ public void write(byte[] b, int off, int len) throws IOException

// Should we aggregate?
int capacity = getBufferSize();
if (!complete && len<=capacity/4)
if (!complete && len<=_commitSize)
{
if (_aggregate == null)
_aggregate = _channel.getByteBufferPool().acquire(capacity, false);
Expand Down Expand Up @@ -271,7 +273,7 @@ public void write(byte[] b, int off, int len) throws IOException

// Should we aggregate?
int capacity = getBufferSize();
if (!complete && len<=capacity/4)
if (!complete && len<=_commitSize)
{
if (_aggregate == null)
_aggregate = _channel.getByteBufferPool().acquire(capacity, false);
Expand All @@ -294,7 +296,7 @@ public void write(byte[] b, int off, int len) throws IOException
_channel.write(_aggregate, complete && len==0);

// should we fill aggregate again from the buffer?
if (len>0 && !complete && len<=_aggregate.capacity()/4)
if (len>0 && !complete && len<=_commitSize)
{
BufferUtil.append(_aggregate, b, off, len);
return;
Expand Down Expand Up @@ -596,7 +598,8 @@ public int getBufferSize()

public void setBufferSize(int size)
{
this._bufferSize = size;
_bufferSize = size;
_commitSize = size;
}

public void resetBuffer()
Expand Down Expand Up @@ -704,12 +707,10 @@ protected boolean process()
return false;
}

// TODO write comments
if (!_complete && _len<BufferUtil.space(_aggregate) && _len<_aggregate.capacity()/4)
if (!_complete && _len<BufferUtil.space(_aggregate) && _len<_commitSize)
{
BufferUtil.put(_buffer,_aggregate);
}
// TODO write comments
else if (_len>0 && !_flushed)
{
_flushed=true;
Expand Down

0 comments on commit ad8db51

Please sign in to comment.