diff src/org/eclipse/jetty/http/HttpGenerator.java @ 1059:013939bfc9e8

remove JBuffer.poke()
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Nov 2016 05:39:33 -0700
parents 419bf9c03d84
children a0abb16cf6e7
line wrap: on
line diff
--- a/src/org/eclipse/jetty/http/HttpGenerator.java	Tue Nov 08 04:17:22 2016 -0700
+++ b/src/org/eclipse/jetty/http/HttpGenerator.java	Tue Nov 08 05:39:33 2016 -0700
@@ -102,7 +102,7 @@
 
 
 	public void shutdown() {
-		if (_persistent!=null && !_persistent && _endp!=null && !_endp.isOutputShutdown())
+		if (_persistent!=null && !_persistent && !_endp.isOutputShutdown())
 		{
 			try
 			{
@@ -176,7 +176,7 @@
 			content.clear();
 			_content=null;
 		}
-		else if (_endp != null && (_buffer==null || _buffer.remaining()==0) && _content.remaining() > 0 && (_last || isCommitted() && _content.remaining()>1024))
+		else if ((_buffer==null || _buffer.remaining()==0) && _content.remaining() > 0 && (_last || isCommitted() && _content.remaining()>1024))
 		{
 			_bypass = true;
 		}
@@ -227,13 +227,13 @@
 		if (_head)
 			return Integer.MAX_VALUE;
 
-		return _buffer.space()-(_contentLength == HttpTokens.CHUNKED_CONTENT?CHUNK_SPACE:0);
+		return _buffer.space();
 	}
 
 	public boolean isBufferFull()
 	{
 		// Should we flush the buffers?
-		return isBufferFull2() || _bufferChunked || _bypass  || (_contentLength == HttpTokens.CHUNKED_CONTENT && _buffer != null && _buffer.space() < CHUNK_SPACE);
+		return isBufferFull2() || _bufferChunked || _bypass /* || (_contentLength == HttpTokens.CHUNKED_CONTENT && _buffer != null && _buffer.space() < CHUNK_SPACE)*/;
 	}
 
 	public void send1xx(int code) throws IOException
@@ -342,7 +342,7 @@
 
 				if (_status<200 && _status>=100 )
 				{
-					_noContent=true;
+					_noContent = true;
 					_content=null;
 					if (_buffer!=null)
 						_buffer.clear();
@@ -357,7 +357,7 @@
 				}
 				else if (_status==204 || _status==304)
 				{
-					_noContent=true;
+					_noContent = true;
 					_content=null;
 					if (_buffer!=null)
 						_buffer.clear();
@@ -664,17 +664,6 @@
 
 			prepareBuffers();
 
-			if (_endp == null)
-			{
-				if (_needCRLF && _buffer!=null)
-					_buffer.put(HttpTokens.CRLF);
-				if (_needEOC && _buffer!=null && !_head)
-					_buffer.put(LAST_CHUNK);
-				_needCRLF=false;
-				_needEOC=false;
-				return 0;
-			}
-
 			int total= 0;
 
 			int len = -1;
@@ -683,7 +672,7 @@
 
 			do
 			{
-				last_flush=to_flush;
+				last_flush = to_flush;
 				switch (to_flush)
 				{
 					case 7:
@@ -721,10 +710,6 @@
 							_buffer.clear();
 							if (_contentLength == HttpTokens.CHUNKED_CONTENT)
 							{
-								// reserve some space for the chunk header
-								_buffer.setPutIndex(CHUNK_SPACE);
-								_buffer.setGetIndex(CHUNK_SPACE);
-
 								// Special case handling for small left over buffer from
 								// an addContent that caused a buffer flush.
 								if (_content != null && _content.remaining() < _buffer.space() && _state != STATE_FLUSHING)
@@ -824,37 +809,17 @@
 						// Prepare a chunk!
 						_bufferChunked = true;
 
-						// Did we leave space at the start of the buffer.
-						//noinspection ConstantConditions
-						if (_buffer.getIndex() == CHUNK_SPACE)
+						if (_header == null)
+							_header = _buffers.getHeader();
+
+						if (_needCRLF)
 						{
-							// Oh yes, goodie! let's use it then!
-							_buffer.poke(_buffer.getIndex() - 2, HttpTokens.CRLF, 0, 2);
-							_buffer.setGetIndex(_buffer.getIndex() - 2);
-							BufferUtil.prependHexInt(_buffer, size);
-
-							if (_needCRLF)
-							{
-								_buffer.poke(_buffer.getIndex() - 2, HttpTokens.CRLF, 0, 2);
-								_buffer.setGetIndex(_buffer.getIndex() - 2);
-								_needCRLF = false;
-							}
+							if (_header.remaining() > 0) throw new IllegalStateException("EOC");
+							_header.put(HttpTokens.CRLF);
+							_needCRLF = false;
 						}
-						else
-						{
-							// No space so lets use a header buffer.
-							if (_header == null)
-								_header = _buffers.getHeader();
-
-							if (_needCRLF)
-							{
-								if (_header.remaining() > 0) throw new IllegalStateException("EOC");
-								_header.put(HttpTokens.CRLF);
-								_needCRLF = false;
-							}
-							BufferUtil.putHexInt(_header, size);
-							_header.put(HttpTokens.CRLF);
-						}
+						BufferUtil.putHexInt(_header, size);
+						_header.put(HttpTokens.CRLF);
 
 						// Add end chunk trailer.
 						if (_buffer.space() >= 2)
@@ -960,7 +925,6 @@
 	private int _status = 0;
 	private int _version = HttpVersions.HTTP_1_1_ORDINAL;
 	private JBuffer _reason;
-	private String _uri;
 
 	private long _contentWritten = 0;
 	private long _contentLength = HttpTokens.UNKNOWN_CONTENT;
@@ -994,7 +958,7 @@
 		_persistent = null;
 		_contentWritten = 0;
 		_contentLength = HttpTokens.UNKNOWN_CONTENT;
-		_content=null;
+		_content = null;
 		if (_buffer!=null)
 			_buffer.clear();
 	}
@@ -1033,9 +997,9 @@
 	public final void setContentLength(long value)
 	{
 		if (value<0)
-			_contentLength=HttpTokens.UNKNOWN_CONTENT;
+			_contentLength = HttpTokens.UNKNOWN_CONTENT;
 		else
-			_contentLength=value;
+			_contentLength = value;
 	}
 
 	public final void setHead(boolean head)
@@ -1050,9 +1014,7 @@
 	 */
 	public final boolean isPersistent()
 	{
-		return _persistent!=null
-		?_persistent.booleanValue()
-		:_version>HttpVersions.HTTP_1_0_ORDINAL;
+		return _persistent!=null ? _persistent.booleanValue() : _version>HttpVersions.HTTP_1_0_ORDINAL;
 	}
 
 	public final void setPersistent(boolean persistent)
@@ -1109,7 +1071,7 @@
 		}
 		else
 		{
-			_contentWritten+=_buffer.remaining();
+			_contentWritten += _buffer.remaining();
 			if (_head)
 				_buffer.clear();
 		}