Mercurial Hosting > luan
changeset 1059:013939bfc9e8
remove JBuffer.poke()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 08 Nov 2016 05:39:33 -0700 |
parents | 419bf9c03d84 |
children | 957f758dcffc |
files | src/org/eclipse/jetty/http/HttpGenerator.java src/org/eclipse/jetty/http/HttpParser.java src/org/eclipse/jetty/io/BufferUtil.java src/org/eclipse/jetty/io/JBuffer.java src/org/eclipse/jetty/server/AbstractHttpConnection.java |
diffstat | 5 files changed, 24 insertions(+), 115 deletions(-) [+] |
line wrap: on
line diff
diff -r 419bf9c03d84 -r 013939bfc9e8 src/org/eclipse/jetty/http/HttpGenerator.java --- 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(); }
diff -r 419bf9c03d84 -r 013939bfc9e8 src/org/eclipse/jetty/http/HttpParser.java --- a/src/org/eclipse/jetty/http/HttpParser.java Tue Nov 08 04:17:22 2016 -0700 +++ b/src/org/eclipse/jetty/http/HttpParser.java Tue Nov 08 05:39:33 2016 -0700 @@ -509,11 +509,11 @@ // value=HttpHeaderValues.CACHE.lookup(value); vo = HttpHeaderValues.CACHE.getOrdinal(value); if (HttpHeaderValues.CHUNKED_ORDINAL == vo) - _contentLength=HttpTokens.CHUNKED_CONTENT; + _contentLength = HttpTokens.CHUNKED_CONTENT; else { if (value.endsWith(HttpHeaderValues.CHUNKED)) - _contentLength=HttpTokens.CHUNKED_CONTENT; + _contentLength = HttpTokens.CHUNKED_CONTENT; else if (value.indexOf(HttpHeaderValues.CHUNKED) >= 0) throw new HttpException(400,null);
diff -r 419bf9c03d84 -r 013939bfc9e8 src/org/eclipse/jetty/io/BufferUtil.java --- a/src/org/eclipse/jetty/io/BufferUtil.java Tue Nov 08 04:17:22 2016 -0700 +++ b/src/org/eclipse/jetty/io/BufferUtil.java Tue Nov 08 05:39:33 2016 -0700 @@ -118,44 +118,6 @@ } } - /* ------------------------------------------------------------ */ - /** - * Add hex integer BEFORE current getIndex. - * @param buffer - * @param n - */ - public static void prependHexInt(JBuffer buffer, int n) - { - if (n==0) - { - int gi=buffer.getIndex(); - buffer.poke(--gi,(byte)'0'); - buffer.setGetIndex(gi); - } - else - { - boolean minus=false; - if (n<0) - { - minus=true; - n=-n; - } - - int gi=buffer.getIndex(); - while(n>0) - { - int d = 0xf&n; - n=n>>4; - buffer.poke(--gi,DIGIT[d]); - } - - if (minus) - buffer.poke(--gi,(byte)'-'); - buffer.setGetIndex(gi); - } - } - - public static void putDecLong(JBuffer buffer, long n) { if (n < 0)
diff -r 419bf9c03d84 -r 013939bfc9e8 src/org/eclipse/jetty/io/JBuffer.java --- a/src/org/eclipse/jetty/io/JBuffer.java Tue Nov 08 04:17:22 2016 -0700 +++ b/src/org/eclipse/jetty/io/JBuffer.java Tue Nov 08 05:39:33 2016 -0700 @@ -184,21 +184,6 @@ } - private JBuffer pokeBuffer(int index) { - JBuffer dup = duplicate(); - dup.setPutIndex(index); - return dup; - } - - public int poke(int index, byte b[], int offset, int length) { - return pokeBuffer(index).put(b,offset,length); - } - - public void poke(int index, byte b) { - pokeBuffer(index).put(b); - } - - public byte get(int index) { return bb.get(index); }
diff -r 419bf9c03d84 -r 013939bfc9e8 src/org/eclipse/jetty/server/AbstractHttpConnection.java --- a/src/org/eclipse/jetty/server/AbstractHttpConnection.java Tue Nov 08 04:17:22 2016 -0700 +++ b/src/org/eclipse/jetty/server/AbstractHttpConnection.java Tue Nov 08 05:39:33 2016 -0700 @@ -845,7 +845,7 @@ max = _generator.prepareUncheckedAddContent(); buffer = _generator.getUncheckedBuffer(); - len=buffer.readFrom(in,max); + len = buffer.readFrom(in,max); } _generator.completeUncheckedAddContent(); _out.flush();