reworked the buffers mechanism to be less conditional

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@396 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2009-06-15 07:11:04 +00:00
parent 1c6a46a8b2
commit 0a8e71e89e
37 changed files with 749 additions and 508 deletions

View File

@ -10,6 +10,7 @@ jetty-7.0.0.M3-SNAPSHOT
+ Added ContinuationThrowable + Added ContinuationThrowable
+ 276545 Quoted cookie paths + 276545 Quoted cookie paths
+ 279725 Support 100 and 102 expectations + 279725 Support 100 and 102 expectations
+ Refactored AbstractBuffers to HttpBuffers for performance
jetty-7.0.0.M2 18 May 2009 jetty-7.0.0.M2 18 May 2009
+ JETTY-937 Work around Sun JVM bugs + JETTY-937 Work around Sun JVM bugs

View File

@ -22,9 +22,9 @@ import java.util.Collection;
import javax.servlet.ServletInputStream; import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpException;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.HttpException;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
@ -42,8 +42,8 @@ public class Ajp13Connection extends HttpConnection
public Ajp13Connection(Connector connector, EndPoint endPoint, Server server) public Ajp13Connection(Connector connector, EndPoint endPoint, Server server)
{ {
super(connector, endPoint, server, super(connector, endPoint, server,
new Ajp13Parser(connector, endPoint), new Ajp13Parser(connector.getRequestBuffers(), endPoint),
new Ajp13Generator(connector, endPoint, connector.getHeaderBufferSize(), connector.getResponseBufferSize()), new Ajp13Generator(connector.getResponseBuffers(), endPoint),
new Ajp13Request() new Ajp13Request()
); );

View File

@ -108,9 +108,9 @@ public class Ajp13Generator extends AbstractGenerator
private boolean _bufferPrepared = false; private boolean _bufferPrepared = false;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public Ajp13Generator(Buffers buffers, EndPoint io, int headerBufferSize, int contentBufferSize) public Ajp13Generator(Buffers buffers, EndPoint io)
{ {
super(buffers, io, headerBufferSize, contentBufferSize); super(buffers, io);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -342,7 +342,7 @@ public class Ajp13Generator extends AbstractGenerator
// get a header buffer // get a header buffer
if (_header == null) if (_header == null)
_header = _buffers.getBuffer(_headerBufferSize); _header = _buffers.getHeader();
Buffer tmpbuf = _buffer; Buffer tmpbuf = _buffer;
_buffer = _header; _buffer = _header;
@ -658,7 +658,7 @@ public class Ajp13Generator extends AbstractGenerator
if (_header == null) if (_header == null)
{ {
_header = _buffers.getBuffer(_headerBufferSize); _header = _buffers.getHeader();
} }
if (_buffer == null && _header != null && _header.space() >= AJP13_MORE_CONTENT.length) if (_buffer == null && _header != null && _header.space() >= AJP13_MORE_CONTENT.length)
@ -709,7 +709,7 @@ public class Ajp13Generator extends AbstractGenerator
{ {
if (_buffer == null) if (_buffer == null)
{ {
_buffer = _buffers.getBuffer(_contentBufferSize); _buffer = _buffers.getBuffer();
_buffer.setPutIndex(7); _buffer.setPutIndex(7);
_buffer.setGetIndex(7); _buffer.setGetIndex(7);
} }
@ -782,14 +782,13 @@ public class Ajp13Generator extends AbstractGenerator
public void sendCPong() throws IOException public void sendCPong() throws IOException
{ {
Buffer buff = _buffers.getBuffer(AJP13_CPONG_RESPONSE.length); Buffer buff = _buffers.getBuffer();
buff.put(AJP13_CPONG_RESPONSE); buff.put(AJP13_CPONG_RESPONSE);
// flushing cpong response // flushing cpong response
do do
{ {
_endp.flush(buff); _endp.flush(buff);
} }
while(buff.length() >0); while(buff.length() >0);
_buffers.returnBuffer(buff); _buffers.returnBuffer(buff);

View File

@ -234,10 +234,8 @@ public class Ajp13Parser implements Parser
if (_buffer == null) if (_buffer == null)
{ {
if (_header == null) if (_header == null)
{ _header = _buffers.getHeader();
_header = _buffers.getBuffer(Ajp13Packet.MAX_PACKET_SIZE);
_header.clear();
}
_buffer = _header; _buffer = _header;
_tok0 = new View(_header); _tok0 = new View(_header);
_tok1 = new View(_header); _tok1 = new View(_header);
@ -491,7 +489,7 @@ public class Ajp13Parser implements Parser
_generator.getBodyChunk(); _generator.getBodyChunk();
if (_buffers != null && _body == null && _buffer == _header && _header.length() <= 0) if (_buffers != null && _body == null && _buffer == _header && _header.length() <= 0)
{ {
_body = _buffers.getBuffer(Ajp13Packet.MAX_PACKET_SIZE); _body = _buffers.getBuffer();
_body.clear(); _body.clear();
} }
_state = STATE_AJP13CHUNK_START; _state = STATE_AJP13CHUNK_START;
@ -503,7 +501,7 @@ public class Ajp13Parser implements Parser
if (_buffers != null && _body == null && _buffer == _header && _contentLength > (_header.capacity() - _header.getIndex())) if (_buffers != null && _body == null && _buffer == _header && _contentLength > (_header.capacity() - _header.getIndex()))
{ {
_body = _buffers.getBuffer(Ajp13Packet.MAX_PACKET_SIZE); _body = _buffers.getBuffer();
_body.clear(); _body.clear();
} }

View File

@ -33,13 +33,13 @@ public class TestAjpParser extends TestCase
byte[] src = TypeUtil.fromHexString(packet); byte[] src = TypeUtil.fromHexString(packet);
ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
EndPoint endp = new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE); EndPoint endp = new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE);
Ajp13Parser parser = new Ajp13Parser(buffers,endp); Ajp13Parser parser = new Ajp13Parser(buffers,endp);
parser.setEventHandler(new EH()); parser.setEventHandler(new EH());
parser.setGenerator(new Ajp13Generator(buffers,endp,0,0)); parser.setGenerator(new Ajp13Generator(buffers,endp));
parser.parseAvailable(); parser.parseAvailable();
@ -51,12 +51,11 @@ public class TestAjpParser extends TestCase
String packet="1234020102020008485454502f312e3100000f2f6363632d7777777777772f61616100000c38382e3838382e38382e383830ffff00116363632e6363636363636363632e636f6d0001bb010009a00b00116363632e6363636363636363632e636f6d00a00e005a4d6f7a696c6c612f352e30202857696e646f77733b20553b2057696e646f7773204e5420352e313b20656e2d55533b2072763a312e382e312e3129204765636b6f2f32303036313230342046697265666f782f322e302e302e3100a0010063746578742f786d6c2c6170706c69636174696f6e2f786d6c2c6170706c69636174696f6e2f7868746d6c2b786d6c2c746578742f68746d6c3b713d302e392c746578742f706c61696e3b713d302e382c696d6167652f706e672c2a2f2a3b713d302e3500a004000e656e2d75732c656e3b713d302e3500a003000c677a69702c6465666c61746500a002001e49534f2d383835392d312c7574662d383b713d302e372c2a3b713d302e3700000a4b6565702d416c69766500000333303000a006000a6b6565702d616c69766500000c4d61782d466f7277617264730000023130000800124448452d5253412d4145533235362d5348410009004039324643303544413043444141443232303137413743443141453939353132413330443938363838423843433041454643364231363035323543433232353341000b0100ff"; String packet="1234020102020008485454502f312e3100000f2f6363632d7777777777772f61616100000c38382e3838382e38382e383830ffff00116363632e6363636363636363632e636f6d0001bb010009a00b00116363632e6363636363636363632e636f6d00a00e005a4d6f7a696c6c612f352e30202857696e646f77733b20553b2057696e646f7773204e5420352e313b20656e2d55533b2072763a312e382e312e3129204765636b6f2f32303036313230342046697265666f782f322e302e302e3100a0010063746578742f786d6c2c6170706c69636174696f6e2f786d6c2c6170706c69636174696f6e2f7868746d6c2b786d6c2c746578742f68746d6c3b713d302e392c746578742f706c61696e3b713d302e382c696d6167652f706e672c2a2f2a3b713d302e3500a004000e656e2d75732c656e3b713d302e3500a003000c677a69702c6465666c61746500a002001e49534f2d383835392d312c7574662d383b713d302e372c2a3b713d302e3700000a4b6565702d416c69766500000333303000a006000a6b6565702d616c69766500000c4d61782d466f7277617264730000023130000800124448452d5253412d4145533235362d5348410009004039324643303544413043444141443232303137413743443141453939353132413330443938363838423843433041454643364231363035323543433232353341000b0100ff";
byte[] src=TypeUtil.fromHexString(packet); byte[] src=TypeUtil.fromHexString(packet);
ByteArrayBuffer buffer=new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer=new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[] SimpleBuffers buffers=new SimpleBuffers(buffer,null);
{ buffer });
EndPoint endp=new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE); EndPoint endp=new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE);
Ajp13Parser parser = new Ajp13Parser(buffers,endp); Ajp13Parser parser = new Ajp13Parser(buffers,endp);
parser.setEventHandler(new EH()); parser.setEventHandler(new EH());
parser.setGenerator(new Ajp13Generator(buffers,endp,0,0)); parser.setGenerator(new Ajp13Generator(buffers,endp));
parser.parse(); parser.parse();
assertTrue(true); assertTrue(true);
} }
@ -66,12 +65,11 @@ public class TestAjpParser extends TestCase
String packet="1234028f02020008485454502f312e3100000d2f666f726d746573742e6a737000000d3139322e3136382e342e31383000ffff00107777772e777265636b6167652e6f726700005000000aa0010063746578742f786d6c2c6170706c69636174696f6e2f786d6c2c6170706c69636174696f6e2f7868746d6c2b786d6c2c746578742f68746d6c3b713d302e392c746578742f706c61696e3b713d302e382c696d6167652f706e672c2a2f2a3b713d302e3500a00200075554462d382c2a00a003000c677a69702c6465666c61746500a004000e656e2d67622c656e3b713d302e3500a006000a6b6565702d616c69766500a00900f95048505345535349443d37626361383232616638333466316465373663633630336366636435313938633b20667041757468436f6f6b69653d433035383430394537393344364245434633324230353234344242303039343230383344443645443533304230454637464137414544413745453231313538333745363033454435364332364446353531383635333335423433374531423637414641343533364345304546323342333642323133374243423932333943363631433131443330393842333938414546334546334146454344423746353842443b204a53455353494f4e49443d7365366331623864663432762e6a657474793300a00b00107777772e777265636b6167652e6f726700000a6b6565702d616c69766500000333303000a00e00654d6f7a696c6c612f352e3020285831313b20553b204c696e7578207838365f36343b20656e2d55533b2072763a312e382e302e3929204765636b6f2f3230303631323035202844656269616e2d312e382e302e392d3129204570697068616e792f322e313400a008000130000600066a657474793300ff"; String packet="1234028f02020008485454502f312e3100000d2f666f726d746573742e6a737000000d3139322e3136382e342e31383000ffff00107777772e777265636b6167652e6f726700005000000aa0010063746578742f786d6c2c6170706c69636174696f6e2f786d6c2c6170706c69636174696f6e2f7868746d6c2b786d6c2c746578742f68746d6c3b713d302e392c746578742f706c61696e3b713d302e382c696d6167652f706e672c2a2f2a3b713d302e3500a00200075554462d382c2a00a003000c677a69702c6465666c61746500a004000e656e2d67622c656e3b713d302e3500a006000a6b6565702d616c69766500a00900f95048505345535349443d37626361383232616638333466316465373663633630336366636435313938633b20667041757468436f6f6b69653d433035383430394537393344364245434633324230353234344242303039343230383344443645443533304230454637464137414544413745453231313538333745363033454435364332364446353531383635333335423433374531423637414641343533364345304546323342333642323133374243423932333943363631433131443330393842333938414546334546334146454344423746353842443b204a53455353494f4e49443d7365366331623864663432762e6a657474793300a00b00107777772e777265636b6167652e6f726700000a6b6565702d616c69766500000333303000a00e00654d6f7a696c6c612f352e3020285831313b20553b204c696e7578207838365f36343b20656e2d55533b2072763a312e382e302e3929204765636b6f2f3230303631323035202844656269616e2d312e382e302e392d3129204570697068616e792f322e313400a008000130000600066a657474793300ff";
byte[] src=TypeUtil.fromHexString(packet); byte[] src=TypeUtil.fromHexString(packet);
ByteArrayBuffer buffer=new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer=new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[] SimpleBuffers buffers=new SimpleBuffers(buffer,null);
{ buffer });
EndPoint endp=new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE); EndPoint endp=new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE);
Ajp13Parser parser = new Ajp13Parser(buffers,endp); Ajp13Parser parser = new Ajp13Parser(buffers,endp);
parser.setEventHandler(new EH()); parser.setEventHandler(new EH());
parser.setGenerator(new Ajp13Generator(buffers,endp,0,0)); parser.setGenerator(new Ajp13Generator(buffers,endp));
parser.parse(); parser.parse();
assertTrue(true); assertTrue(true);
} }
@ -83,13 +81,13 @@ public class TestAjpParser extends TestCase
byte[] src = TypeUtil.fromHexString(packet); byte[] src = TypeUtil.fromHexString(packet);
ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
EndPoint endp = new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE); EndPoint endp = new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE);
Ajp13Parser parser = new Ajp13Parser(buffers,endp); Ajp13Parser parser = new Ajp13Parser(buffers,endp);
parser.setEventHandler(new EH()); parser.setEventHandler(new EH());
parser.setGenerator(new Ajp13Generator(buffers,endp,0,0)); parser.setGenerator(new Ajp13Generator(buffers,endp));
parser.parseAvailable(); parser.parseAvailable();
@ -102,13 +100,13 @@ public class TestAjpParser extends TestCase
byte[] src = TypeUtil.fromHexString(packet); byte[] src = TypeUtil.fromHexString(packet);
ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
EndPoint endp = new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE); EndPoint endp = new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE);
Ajp13Parser parser = new Ajp13Parser(buffers,endp); Ajp13Parser parser = new Ajp13Parser(buffers,endp);
parser.setEventHandler(new EH()); parser.setEventHandler(new EH());
parser.setGenerator(new Ajp13Generator(buffers,endp,0,0)); parser.setGenerator(new Ajp13Generator(buffers,endp));
parser.parseAvailable(); parser.parseAvailable();
@ -129,14 +127,14 @@ public class TestAjpParser extends TestCase
System.arraycopy(src,src.length-f,frag1,0,f); System.arraycopy(src,src.length-f,frag1,0,f);
ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
ByteArrayEndPoint endp = new ByteArrayEndPoint(frag0,Ajp13Packet.MAX_PACKET_SIZE); ByteArrayEndPoint endp = new ByteArrayEndPoint(frag0,Ajp13Packet.MAX_PACKET_SIZE);
endp.setNonBlocking(true); endp.setNonBlocking(true);
Ajp13Parser parser = new Ajp13Parser(buffers,endp); Ajp13Parser parser = new Ajp13Parser(buffers,endp);
parser.setEventHandler(new EH()); parser.setEventHandler(new EH());
parser.setGenerator(new Ajp13Generator(buffers,endp,0,0)); parser.setGenerator(new Ajp13Generator(buffers,endp));
parser.parseNext(); parser.parseNext();
endp.setIn(new ByteArrayBuffer(frag1)); endp.setIn(new ByteArrayBuffer(frag1));
@ -153,13 +151,12 @@ public class TestAjpParser extends TestCase
String packet=getTestHeader(); String packet=getTestHeader();
byte[] src=TypeUtil.fromHexString(packet); byte[] src=TypeUtil.fromHexString(packet);
ByteArrayBuffer buffer=new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer=new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[] SimpleBuffers buffers=new SimpleBuffers(buffer,null);
{ buffer });
ByteArrayEndPoint endp=new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE); ByteArrayEndPoint endp=new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE);
endp.setNonBlocking(true); endp.setNonBlocking(true);
final int count[]={0}; final int count[]={0};
Ajp13Generator gen = new Ajp13Generator(buffers,endp,0,0) Ajp13Generator gen = new Ajp13Generator(buffers,endp)
{ {
public void getBodyChunk() throws IOException public void getBodyChunk() throws IOException
{ {
@ -198,13 +195,12 @@ public class TestAjpParser extends TestCase
String packet="123400ff02040008485454502f312e3100000f2f746573742f64756d702f696e666f0000093132372e302e302e3100ffff00096c6f63616c686f7374000050000007a00e000d4a6176612f312e352e305f313100a00b00096c6f63616c686f737400a0010034746578742f68746d6c2c20696d6167652f6769662c20696d6167652f6a7065672c202a3b20713d2e322c202a2f2a3b20713d2e3200a006000a6b6565702d616c69766500a00700216170706c69636174696f6e2f782d7777772d666f726d2d75726c656e636f6465640000115472616e736665722d456e636f64696e670000076368756e6b656400000c4d61782d466f727761726473000002313000ff"; String packet="123400ff02040008485454502f312e3100000f2f746573742f64756d702f696e666f0000093132372e302e302e3100ffff00096c6f63616c686f7374000050000007a00e000d4a6176612f312e352e305f313100a00b00096c6f63616c686f737400a0010034746578742f68746d6c2c20696d6167652f6769662c20696d6167652f6a7065672c202a3b20713d2e322c202a2f2a3b20713d2e3200a006000a6b6565702d616c69766500a00700216170706c69636174696f6e2f782d7777772d666f726d2d75726c656e636f6465640000115472616e736665722d456e636f64696e670000076368756e6b656400000c4d61782d466f727761726473000002313000ff";
byte[] src=TypeUtil.fromHexString(packet); byte[] src=TypeUtil.fromHexString(packet);
ByteArrayBuffer buffer=new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer=new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[] SimpleBuffers buffers=new SimpleBuffers(buffer,null);
{ buffer });
ByteArrayEndPoint endp=new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE); ByteArrayEndPoint endp=new ByteArrayEndPoint(src,Ajp13Packet.MAX_PACKET_SIZE);
endp.setNonBlocking(true); endp.setNonBlocking(true);
final int count[]={0}; final int count[]={0};
Ajp13Generator gen = new Ajp13Generator(buffers,endp,0,0) Ajp13Generator gen = new Ajp13Generator(buffers,endp)
{ {
public void getBodyChunk() throws IOException public void getBodyChunk() throws IOException
{ {
@ -258,14 +254,14 @@ public class TestAjpParser extends TestCase
System.arraycopy(src,src.length-f,frag1,0,f); System.arraycopy(src,src.length-f,frag1,0,f);
ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
ByteArrayEndPoint endp = new ByteArrayEndPoint(frag0,Ajp13Packet.MAX_PACKET_SIZE); ByteArrayEndPoint endp = new ByteArrayEndPoint(frag0,Ajp13Packet.MAX_PACKET_SIZE);
endp.setNonBlocking(true); endp.setNonBlocking(true);
Ajp13Parser parser = new Ajp13Parser(buffers,endp); Ajp13Parser parser = new Ajp13Parser(buffers,endp);
parser.setEventHandler(new EH()); parser.setEventHandler(new EH());
parser.setGenerator(new Ajp13Generator(buffers,endp,0,0)); parser.setGenerator(new Ajp13Generator(buffers,endp));
parser.parseNext(); parser.parseNext();
endp.setIn(new ByteArrayBuffer(frag1)); endp.setIn(new ByteArrayBuffer(frag1));
@ -291,14 +287,14 @@ public class TestAjpParser extends TestCase
System.arraycopy(src,src.length-f,frag1,0,f); System.arraycopy(src,src.length-f,frag1,0,f);
ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE); ByteArrayBuffer buffer= new ByteArrayBuffer(Ajp13Packet.MAX_PACKET_SIZE);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
ByteArrayEndPoint endp = new ByteArrayEndPoint(frag0,Ajp13Packet.MAX_PACKET_SIZE); ByteArrayEndPoint endp = new ByteArrayEndPoint(frag0,Ajp13Packet.MAX_PACKET_SIZE);
endp.setNonBlocking(true); endp.setNonBlocking(true);
Ajp13Parser parser = new Ajp13Parser(buffers,endp); Ajp13Parser parser = new Ajp13Parser(buffers,endp);
parser.setEventHandler(new EH()); parser.setEventHandler(new EH());
parser.setGenerator(new Ajp13Generator(buffers,endp,0,0)); parser.setGenerator(new Ajp13Generator(buffers,endp));
parser.parseNext(); parser.parseNext();
endp.setIn(new ByteArrayBuffer(frag1)); endp.setIn(new ByteArrayBuffer(frag1));

View File

@ -35,8 +35,8 @@ import javax.net.ssl.X509TrustManager;
import org.eclipse.jetty.client.security.Authorization; import org.eclipse.jetty.client.security.Authorization;
import org.eclipse.jetty.client.security.RealmResolver; import org.eclipse.jetty.client.security.RealmResolver;
import org.eclipse.jetty.http.HttpBuffers;
import org.eclipse.jetty.http.HttpSchemes; import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.io.AbstractBuffers;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.nio.DirectNIOBuffer; import org.eclipse.jetty.io.nio.DirectNIOBuffer;
@ -78,7 +78,7 @@ import org.eclipse.jetty.util.thread.Timeout;
* @see {@link HttpExchange} * @see {@link HttpExchange}
* @see {@link HttpDestination} * @see {@link HttpDestination}
*/ */
public class HttpClient extends AbstractBuffers implements Attributes public class HttpClient extends HttpBuffers implements Attributes
{ {
public static final int CONNECTOR_SOCKET = 0; public static final int CONNECTOR_SOCKET = 0;
public static final int CONNECTOR_SELECT_CHANNEL = 2; public static final int CONNECTOR_SELECT_CHANNEL = 2;
@ -341,26 +341,50 @@ public class HttpClient extends AbstractBuffers implements Attributes
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* Create a new NIO buffer. If using direct buffers, it will create a direct * @see org.eclipse.jetty.http.HttpBuffers#newRequestBuffer(int)
* NIO buffer, other than an indirect buffer.
*/ */
public Buffer newBuffer(int size) @Override
protected Buffer newRequestBuffer(int size)
{ {
if (_connectorType != CONNECTOR_SOCKET) if (_connectorType == CONNECTOR_SOCKET)
{
Buffer buf = null;
if (size==getHeaderBufferSize())
buf=new IndirectNIOBuffer(size);
else if (_useDirectBuffers)
buf=new DirectNIOBuffer(size);
else
buf=new IndirectNIOBuffer(size);
return buf;
}
else
{
return new ByteArrayBuffer(size); return new ByteArrayBuffer(size);
} return _useDirectBuffers?new DirectNIOBuffer(size):new IndirectNIOBuffer(size);
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.http.HttpBuffers#newRequestHeader(int)
*/
@Override
protected Buffer newRequestHeader(int size)
{
if (_connectorType == CONNECTOR_SOCKET)
return new ByteArrayBuffer(size);
return new IndirectNIOBuffer(size);
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.http.HttpBuffers#newResponseBuffer(int)
*/
@Override
protected Buffer newResponseBuffer(int size)
{
if (_connectorType == CONNECTOR_SOCKET)
return new ByteArrayBuffer(size);
return _useDirectBuffers?new DirectNIOBuffer(size):new IndirectNIOBuffer(size);
}
/* ------------------------------------------------------------ */
/**
* @see org.eclipse.jetty.http.HttpBuffers#newResponseHeader(int)
*/
@Override
protected Buffer newResponseHeader(int size)
{
if (_connectorType == CONNECTOR_SOCKET)
return new ByteArrayBuffer(size);
return new IndirectNIOBuffer(size);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */

View File

@ -108,11 +108,11 @@ public class HttpConnection implements Connection
}; };
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
HttpConnection(Buffers buffers, EndPoint endp, int hbs, int cbs) HttpConnection(Buffers requestBuffers, Buffers responseBuffers, EndPoint endp)
{ {
_endp = endp; _endp = endp;
_generator = new HttpGenerator(buffers,endp,hbs,cbs); _generator = new HttpGenerator(requestBuffers,endp);
_parser = new HttpParser(buffers,endp,new Handler(),hbs,cbs); _parser = new HttpParser(responseBuffers,endp,new Handler());
} }
public void setReserved (boolean reserved) public void setReserved (boolean reserved)

View File

@ -19,14 +19,17 @@ import java.nio.channels.SocketChannel;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSession;
import org.eclipse.jetty.http.HttpBuffers;
import org.eclipse.jetty.http.HttpMethods; import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.http.HttpVersions; import org.eclipse.jetty.http.HttpVersions;
import org.eclipse.jetty.http.ssl.SslSelectChannelEndPoint; import org.eclipse.jetty.http.ssl.SslSelectChannelEndPoint;
import org.eclipse.jetty.io.AbstractBuffers;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.Buffers; import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.ThreadLocalBuffers;
import org.eclipse.jetty.io.nio.DirectNIOBuffer;
import org.eclipse.jetty.io.nio.IndirectNIOBuffer; import org.eclipse.jetty.io.nio.IndirectNIOBuffer;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint; import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.io.nio.SelectorManager; import org.eclipse.jetty.io.nio.SelectorManager;
@ -40,7 +43,7 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
private Buffers _sslBuffers; private Buffers _sslBuffers;
private boolean _blockingConnect; private boolean _blockingConnect;
SelectorManager _selectorManager=new Manager(); Manager _selectorManager=new Manager();
/** /**
* @param httpClient * @param httpClient
@ -71,7 +74,32 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
protected void doStart() throws Exception protected void doStart() throws Exception
{ {
super.doStart();
_selectorManager.start(); _selectorManager.start();
SSLEngine sslEngine=_selectorManager.newSslEngine();
SSLSession ssl_session=sslEngine.getSession();
ThreadLocalBuffers buffers = new ThreadLocalBuffers()
{
@Override
protected Buffer newBuffer(int size)
{
// TODO indirect?
return new DirectNIOBuffer(size);
}
@Override
protected Buffer newHeader(int size)
{
// TODO indirect?
return new DirectNIOBuffer(size);
}
};
buffers.setBufferSize(ssl_session.getApplicationBufferSize());
buffers.setHeaderSize(ssl_session.getPacketBufferSize());
_sslBuffers=buffers;
_httpClient._threadPool.dispatch(this); _httpClient._threadPool.dispatch(this);
} }
@ -134,7 +162,7 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint) protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
{ {
return new HttpConnection(_httpClient,endpoint,SelectConnector.this._httpClient.getHeaderBufferSize(),SelectConnector.this._httpClient.getRequestBufferSize()); return new HttpConnection(_httpClient.getRequestBuffers(),_httpClient.getResponseBuffers(),endpoint);
} }
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException
@ -180,29 +208,8 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
sslEngine.setUseClientMode(true); sslEngine.setUseClientMode(true);
sslEngine.beginHandshake(); sslEngine.beginHandshake();
if (_sslBuffers==null)
{
AbstractBuffers buffers = new AbstractBuffers()
{
public Buffer newBuffer( int size )
{
return new IndirectNIOBuffer( size);
}
};
buffers.setRequestBufferSize( sslEngine.getSession().getPacketBufferSize());
buffers.setResponseBufferSize(sslEngine.getSession().getApplicationBufferSize());
try
{
buffers.start();
}
catch(Exception e)
{
throw new IllegalStateException(e);
}
_sslBuffers=buffers;
}
return sslEngine; return sslEngine;
} }

View File

@ -59,7 +59,7 @@ class SocketConnector extends AbstractLifeCycle implements HttpClient.Connector
EndPoint endpoint=new SocketEndPoint(socket); EndPoint endpoint=new SocketEndPoint(socket);
final HttpConnection connection=new HttpConnection(_httpClient,endpoint,_httpClient.getHeaderBufferSize(),_httpClient.getRequestBufferSize()); final HttpConnection connection=new HttpConnection(_httpClient.getRequestBuffers(),_httpClient.getResponseBuffers(),endpoint);
connection.setDestination(destination); connection.setDestination(destination);
destination.onNewConnection(connection); destination.onNewConnection(connection);
_httpClient.getThreadPool().dispatch(new Runnable() _httpClient.getThreadPool().dispatch(new Runnable()

View File

@ -49,8 +49,6 @@ public abstract class AbstractGenerator implements Generator
protected final Buffers _buffers; // source of buffers protected final Buffers _buffers; // source of buffers
protected final EndPoint _endp; protected final EndPoint _endp;
protected final int _headerBufferSize;
protected int _contentBufferSize;
protected int _state = STATE_HEADER; protected int _state = STATE_HEADER;
@ -83,12 +81,10 @@ public abstract class AbstractGenerator implements Generator
* @param headerBufferSize Size of the buffer to allocate for HTTP header * @param headerBufferSize Size of the buffer to allocate for HTTP header
* @param contentBufferSize Size of the buffer to allocate for HTTP content * @param contentBufferSize Size of the buffer to allocate for HTTP content
*/ */
public AbstractGenerator(Buffers buffers, EndPoint io, int headerBufferSize, int contentBufferSize) public AbstractGenerator(Buffers buffers, EndPoint io)
{ {
this._buffers = buffers; this._buffers = buffers;
this._endp = io; this._endp = io;
_headerBufferSize=headerBufferSize;
_contentBufferSize=contentBufferSize;
} }
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
@ -112,17 +108,15 @@ public abstract class AbstractGenerator implements Generator
_contentLength = HttpTokens.UNKNOWN_CONTENT; _contentLength = HttpTokens.UNKNOWN_CONTENT;
// always return the buffer // always return the buffer
Buffer buffer=_buffer; if (_buffer!=null)
_buffers.returnBuffer(_buffer);
_buffer=null; _buffer=null;
if (buffer!=null && _header!=buffer)
_buffers.returnBuffer(buffer);
if (returnBuffers) if (returnBuffers)
{ {
buffer=_header; if (_header!=null)
_buffers.returnBuffer(_header);
_header=null; _header=null;
if (buffer!=null)
_buffers.returnBuffer(buffer);
} }
else if (_header != null) else if (_header != null)
_header.clear(); _header.clear();
@ -152,7 +146,9 @@ public abstract class AbstractGenerator implements Generator
*/ */
public int getContentBufferSize() public int getContentBufferSize()
{ {
return _contentBufferSize; if (_buffer==null)
_buffer=_buffers.getBuffer();
return _buffer.capacity();
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -161,12 +157,13 @@ public abstract class AbstractGenerator implements Generator
*/ */
public void increaseContentBufferSize(int contentBufferSize) public void increaseContentBufferSize(int contentBufferSize)
{ {
if (contentBufferSize > _contentBufferSize) if (_buffer==null)
_buffer=_buffers.getBuffer();
if (contentBufferSize > _buffer.capacity())
{ {
_contentBufferSize = contentBufferSize;
if (_buffer != null) if (_buffer != null)
{ {
Buffer nb = _buffers.getBuffer(_contentBufferSize); Buffer nb = _buffers.getBuffer(contentBufferSize);
nb.put(_buffer); nb.put(_buffer);
_buffers.returnBuffer(_buffer); _buffers.returnBuffer(_buffer);
_buffer = nb; _buffer = nb;
@ -312,8 +309,10 @@ public abstract class AbstractGenerator implements Generator
if (reason!=null) if (reason!=null)
{ {
int len=reason.length(); int len=reason.length();
if (len>_headerBufferSize/2)
len=_headerBufferSize/2; // TODO don't hard code
if (len>1024)
len=1024;
_reason=new ByteArrayBuffer(len); _reason=new ByteArrayBuffer(len);
for (int i=0;i<len;i++) for (int i=0;i<len;i++)
{ {

View File

@ -0,0 +1,181 @@
// ========================================================================
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.http;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.ThreadLocalBuffers;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
/* ------------------------------------------------------------ */
/** Abstract Buffer pool.
* simple unbounded pool of buffers for header, request and response sizes.
*
*/
public abstract class HttpBuffers extends AbstractLifeCycle
{
private final ThreadLocalBuffers _requestBuffers = new ThreadLocalBuffers()
{
@Override
protected Buffer newBuffer(int size)
{
return newRequestBuffer(size);
}
@Override
protected Buffer newHeader(int size)
{
return newRequestHeader(size);
}
};
private final ThreadLocalBuffers _responseBuffers = new ThreadLocalBuffers()
{
@Override
protected Buffer newBuffer(int size)
{
return newResponseBuffer(size);
}
@Override
protected Buffer newHeader(int size)
{
return newResponseHeader(size);
}
};
public HttpBuffers()
{
super();
_requestBuffers.setBufferSize(8*1024);
_requestBuffers.setHeaderSize(6*1024);
_responseBuffers.setBufferSize(12*1024);
_responseBuffers.setHeaderSize(6*1024);
}
protected void doStart()
throws Exception
{
super.doStart();
}
/**
* @return Returns the headerBufferSize.
* @deprecated use {@link #getRequestHeaderSize()} or {@link #getResponseHeaderSize()}
*/
public int getHeaderBufferSize()
{
return _requestBuffers.getHeaderSize();
}
public Buffers getRequestBuffers()
{
return _requestBuffers;
}
/**
* @return Returns the requestBufferSize.
*/
public int getRequestBufferSize()
{
return _requestBuffers.getBufferSize();
}
/**
* @return Returns the request header size.
*/
public int getRequestHeaderSize()
{
return _requestBuffers.getHeaderSize();
}
public Buffers getResponseBuffers()
{
return _requestBuffers;
}
/**
* @return Returns the responseBufferSize.
*/
public int getResponseBufferSize()
{
return _responseBuffers.getBufferSize();
}
/**
* @return Returns the response header size.
*/
public int getResponseHeaderSize()
{
return _responseBuffers.getHeaderSize();
}
protected abstract Buffer newRequestBuffer(int size);
protected abstract Buffer newRequestHeader(int size);
protected abstract Buffer newResponseBuffer(int size);
protected abstract Buffer newResponseHeader(int size);
/**
* @param headerBufferSize The headerBufferSize to set.
* @deprecated
*/
public void setHeaderBufferSize( int headerBufferSize )
{
setRequestHeaderSize(headerBufferSize);
setResponseHeaderSize(headerBufferSize);
}
/**
* @param size The requestBufferSize to set.
*/
public void setRequestBufferSize( int size )
{
if (isStarted())
throw new IllegalStateException();
_requestBuffers.setBufferSize(size);
}
/**
* @param size
*/
public void setRequestHeaderSize( int size )
{
if (isStarted())
throw new IllegalStateException();
_requestBuffers.setHeaderSize(size);
}
/**
* @param size The response buffer size in bytes.
*/
public void setResponseBufferSize( int size )
{
if (isStarted())
throw new IllegalStateException();
_responseBuffers.setBufferSize(size);
}
/**
* @param size
*/
public void setResponseHeaderSize( int size )
{
if (isStarted())
throw new IllegalStateException();
_responseBuffers.setHeaderSize(size);
}
}

View File

@ -11,7 +11,7 @@
// You may elect to redistribute this code under either of these licenses. // You may elect to redistribute this code under either of these licenses.
// ======================================================================== // ========================================================================
package org.eclipse.jetty.io; package org.eclipse.jetty.http;
import java.io.IOException; import java.io.IOException;

View File

@ -115,9 +115,9 @@ public class HttpGenerator extends AbstractGenerator
* @param headerBufferSize Size of the buffer to allocate for HTTP header * @param headerBufferSize Size of the buffer to allocate for HTTP header
* @param contentBufferSize Size of the buffer to allocate for HTTP content * @param contentBufferSize Size of the buffer to allocate for HTTP content
*/ */
public HttpGenerator(Buffers buffers, EndPoint io, int headerBufferSize, int contentBufferSize) public HttpGenerator(Buffers buffers, EndPoint io)
{ {
super(buffers,io,headerBufferSize,contentBufferSize); super(buffers,io);
} }
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
@ -188,7 +188,7 @@ public class HttpGenerator extends AbstractGenerator
{ {
// Yes - so we better check we have a buffer // Yes - so we better check we have a buffer
if (_buffer == null) if (_buffer == null)
_buffer = _buffers.getBuffer(_contentBufferSize); _buffer = _buffers.getBuffer();
// Copy _content to buffer; // Copy _content to buffer;
int len=_buffer.put(_content); int len=_buffer.put(_content);
@ -255,7 +255,7 @@ public class HttpGenerator extends AbstractGenerator
// we better check we have a buffer // we better check we have a buffer
if (_buffer == null) if (_buffer == null)
_buffer = _buffers.getBuffer(_contentBufferSize); _buffer = _buffers.getBuffer();
// Copy _content to buffer; // Copy _content to buffer;
_buffer.put(b); _buffer.put(b);
@ -288,7 +288,7 @@ public class HttpGenerator extends AbstractGenerator
// we better check we have a buffer // we better check we have a buffer
if (_buffer == null) if (_buffer == null)
_buffer = _buffers.getBuffer(_contentBufferSize); _buffer = _buffers.getBuffer();
_contentWritten-=_buffer.length(); _contentWritten-=_buffer.length();
@ -323,7 +323,7 @@ public class HttpGenerator extends AbstractGenerator
// get a header buffer // get a header buffer
if (_header == null) if (_header == null)
_header = _buffers.getBuffer(_headerBufferSize); _header = _buffers.getHeader();
boolean has_server = false; boolean has_server = false;

View File

@ -21,7 +21,6 @@ import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.HttpException;
import org.eclipse.jetty.io.View; import org.eclipse.jetty.io.View;
import org.eclipse.jetty.io.BufferCache.CachedBuffer; import org.eclipse.jetty.io.BufferCache.CachedBuffer;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
@ -62,9 +61,6 @@ public class HttpParser implements Parser
private Buffer _body; // Buffer for large content private Buffer _body; // Buffer for large content
private Buffer _buffer; // The current buffer in use (either _header or _content) private Buffer _buffer; // The current buffer in use (either _header or _content)
private final View _contentView=new View(); // View of the content in the buffer for {@link Input} private final View _contentView=new View(); // View of the content in the buffer for {@link Input}
private int _headerBufferSize;
private int _contentBufferSize;
private CachedBuffer _cached; private CachedBuffer _cached;
private View.CaseInsensitive _tok0; // Saved token: header name, request method or response version private View.CaseInsensitive _tok0; // Saved token: header name, request method or response version
private View.CaseInsensitive _tok1; // Saved token: header value, request URI or response code private View.CaseInsensitive _tok1; // Saved token: header value, request URI or response code
@ -108,13 +104,11 @@ public class HttpParser implements Parser
* @param headerBufferSize size in bytes of header buffer * @param headerBufferSize size in bytes of header buffer
* @param contentBufferSize size in bytes of content buffer * @param contentBufferSize size in bytes of content buffer
*/ */
public HttpParser(Buffers buffers, EndPoint endp, EventHandler handler, int headerBufferSize, int contentBufferSize) public HttpParser(Buffers buffers, EndPoint endp, EventHandler handler)
{ {
_buffers=buffers; _buffers=buffers;
_endp=endp; _endp=endp;
_handler=handler; _handler=handler;
_headerBufferSize=headerBufferSize;
_contentBufferSize=contentBufferSize;
} }
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
@ -240,7 +234,7 @@ public class HttpParser implements Parser
{ {
if (_header == null) if (_header == null)
{ {
_header=_buffers.getBuffer(_headerBufferSize); _header=_buffers.getHeader();
} }
_buffer=_header; _buffer=_header;
_tok0=new View.CaseInsensitive(_header); _tok0=new View.CaseInsensitive(_header);
@ -522,7 +516,7 @@ public class HttpParser implements Parser
case HttpTokens.EOF_CONTENT: case HttpTokens.EOF_CONTENT:
_state=STATE_EOF_CONTENT; _state=STATE_EOF_CONTENT;
if(_body==null && _buffers!=null) if(_body==null && _buffers!=null)
_body=_buffers.getBuffer(_contentBufferSize); _body=_buffers.getBuffer();
_handler.headerComplete(); // May recurse here ! _handler.headerComplete(); // May recurse here !
break; break;
@ -530,7 +524,7 @@ public class HttpParser implements Parser
case HttpTokens.CHUNKED_CONTENT: case HttpTokens.CHUNKED_CONTENT:
_state=STATE_CHUNKED_CONTENT; _state=STATE_CHUNKED_CONTENT;
if (_body==null && _buffers!=null) if (_body==null && _buffers!=null)
_body=_buffers.getBuffer(_contentBufferSize); _body=_buffers.getBuffer();
_handler.headerComplete(); // May recurse here ! _handler.headerComplete(); // May recurse here !
break; break;
@ -544,7 +538,7 @@ public class HttpParser implements Parser
_state=STATE_CONTENT; _state=STATE_CONTENT;
if(_forceContentBuffer || if(_forceContentBuffer ||
(_buffers!=null && _body==null && _buffer==_header && _contentLength>=(_header.capacity()-_header.getIndex()))) (_buffers!=null && _body==null && _buffer==_header && _contentLength>=(_header.capacity()-_header.getIndex())))
_body=_buffers.getBuffer(_contentBufferSize); _body=_buffers.getBuffer();
_handler.headerComplete(); // May recurse here ! _handler.headerComplete(); // May recurse here !
break; break;
} }
@ -957,7 +951,6 @@ public class HttpParser implements Parser
} }
} }
if (_header!=null) if (_header!=null)
{ {
_header.setMarkIndex(-1); _header.setMarkIndex(-1);
@ -965,7 +958,6 @@ public class HttpParser implements Parser
{ {
_buffers.returnBuffer(_header); _buffers.returnBuffer(_header);
_header=null; _header=null;
_buffer=null;
} }
else else
{ {
@ -1004,7 +996,7 @@ public class HttpParser implements Parser
{ {
if (_header == null) if (_header == null)
{ {
_header=_buffers.getBuffer(_headerBufferSize); _header=_buffers.getHeader();
} }
return _header; return _header;
} }

View File

@ -26,6 +26,7 @@ import javax.net.ssl.SSLEngineResult.HandshakeStatus;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.Buffers; import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.nio.DirectNIOBuffer;
import org.eclipse.jetty.io.nio.NIOBuffer; import org.eclipse.jetty.io.nio.NIOBuffer;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint; import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.io.nio.SelectorManager; import org.eclipse.jetty.io.nio.SelectorManager;
@ -86,9 +87,9 @@ public class SslSelectChannelEndPoint extends SelectChannelEndPoint
_session=engine.getSession(); _session=engine.getSession();
// TODO pool buffers and use only when needed. // TODO pool buffers and use only when needed.
_outNIOBuffer=(NIOBuffer)buffers.getBuffer(_session.getPacketBufferSize()); _outNIOBuffer=(NIOBuffer)_buffers.getBuffer(_session.getPacketBufferSize());
_outBuffer=_outNIOBuffer.getByteBuffer(); _outBuffer=_outNIOBuffer.getByteBuffer();
_inNIOBuffer=(NIOBuffer)buffers.getBuffer(_session.getPacketBufferSize()); _inNIOBuffer=(NIOBuffer)_buffers.getBuffer(_session.getPacketBufferSize());
_inBuffer=_inNIOBuffer.getByteBuffer(); _inBuffer=_inNIOBuffer.getByteBuffer();
// h.append("CONSTRUCTED\n"); // h.append("CONSTRUCTED\n");

View File

@ -39,7 +39,7 @@ public class HttpGeneratorClientTest extends TestCase
Buffer bb=new ByteArrayBuffer(8096); Buffer bb=new ByteArrayBuffer(8096);
Buffer sb=new ByteArrayBuffer(1500); Buffer sb=new ByteArrayBuffer(1500);
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096); ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
HttpGenerator generator = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity()); HttpGenerator generator = new HttpGenerator(new SimpleBuffers(sb,bb),endp);
generator.setRequest("GET","/usr"); generator.setRequest("GET","/usr");
@ -67,7 +67,7 @@ public class HttpGeneratorClientTest extends TestCase
Buffer bb=new ByteArrayBuffer(8096); Buffer bb=new ByteArrayBuffer(8096);
Buffer sb=new ByteArrayBuffer(1500); Buffer sb=new ByteArrayBuffer(1500);
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096); ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
HttpGenerator generator = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity()); HttpGenerator generator = new HttpGenerator(new SimpleBuffers(sb,bb),endp);
generator.setRequest("GET","/usr"); generator.setRequest("GET","/usr");
@ -94,7 +94,7 @@ public class HttpGeneratorClientTest extends TestCase
Buffer bb=new ByteArrayBuffer(8096); Buffer bb=new ByteArrayBuffer(8096);
Buffer sb=new ByteArrayBuffer(1500); Buffer sb=new ByteArrayBuffer(1500);
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096); ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
HttpGenerator generator = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity()); HttpGenerator generator = new HttpGenerator(new SimpleBuffers(sb,bb),endp);
generator.setRequest("GET","/usr"); generator.setRequest("GET","/usr");
@ -122,7 +122,7 @@ public class HttpGeneratorClientTest extends TestCase
Buffer sb=new ByteArrayBuffer(1500); Buffer sb=new ByteArrayBuffer(1500);
HttpFields fields = new HttpFields(); HttpFields fields = new HttpFields();
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096); ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
HttpGenerator hb = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity()); HttpGenerator hb = new HttpGenerator(new SimpleBuffers(sb,bb),endp);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser=null; HttpParser parser=null;

View File

@ -47,7 +47,7 @@ public class HttpGeneratorTest extends TestCase
Buffer sb=new ByteArrayBuffer(1500); Buffer sb=new ByteArrayBuffer(1500);
HttpFields fields = new HttpFields(); HttpFields fields = new HttpFields();
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096); ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
HttpGenerator hb = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity()); HttpGenerator hb = new HttpGenerator(new SimpleBuffers(sb,bb),endp);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser=null; HttpParser parser=null;

View File

@ -69,10 +69,10 @@ public class HttpParserTest extends TestCase
StringEndPoint io=new StringEndPoint(); StringEndPoint io=new StringEndPoint();
io.setInput("POST /foo HTTP/1.0\015\012" + "\015\012"); io.setInput("POST /foo HTTP/1.0\015\012" + "\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("POST", f0); assertEquals("POST", f0);
assertEquals("/foo", f1); assertEquals("/foo", f1);
@ -86,11 +86,11 @@ public class HttpParserTest extends TestCase
StringEndPoint io=new StringEndPoint(); StringEndPoint io=new StringEndPoint();
io.setInput("GET /999\015\012"); io.setInput("GET /999\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
f2= null; f2= null;
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("GET", f0); assertEquals("GET", f0);
assertEquals("/999", f1); assertEquals("/999", f1);
@ -104,11 +104,11 @@ public class HttpParserTest extends TestCase
StringEndPoint io=new StringEndPoint(); StringEndPoint io=new StringEndPoint();
io.setInput("POST /222 \015\012"); io.setInput("POST /222 \015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
f2= null; f2= null;
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("POST", f0); assertEquals("POST", f0);
assertEquals("/222", f1); assertEquals("/222", f1);
@ -122,10 +122,10 @@ public class HttpParserTest extends TestCase
StringEndPoint io=new StringEndPoint(); StringEndPoint io=new StringEndPoint();
io.setInput("POST /fo\u0690 HTTP/1.0\015\012" + "\015\012"); io.setInput("POST /fo\u0690 HTTP/1.0\015\012" + "\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("POST", f0); assertEquals("POST", f0);
assertEquals("/fo\u0690", f1); assertEquals("/fo\u0690", f1);
@ -139,10 +139,10 @@ public class HttpParserTest extends TestCase
StringEndPoint io=new StringEndPoint(); StringEndPoint io=new StringEndPoint();
io.setInput("POST /foo?param=\u0690 HTTP/1.0\015\012" + "\015\012"); io.setInput("POST /foo?param=\u0690 HTTP/1.0\015\012" + "\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("POST", f0); assertEquals("POST", f0);
assertEquals("/foo?param=\u0690", f1); assertEquals("/foo?param=\u0690", f1);
@ -156,10 +156,10 @@ public class HttpParserTest extends TestCase
StringEndPoint io=new StringEndPoint(); StringEndPoint io=new StringEndPoint();
io.setInput("CONNECT 192.168.1.2:80 HTTP/1.1\015\012" + "\015\012"); io.setInput("CONNECT 192.168.1.2:80 HTTP/1.1\015\012" + "\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertTrue(handler.request); assertTrue(handler.request);
assertEquals("CONNECT", f0); assertEquals("CONNECT", f0);
@ -184,10 +184,10 @@ public class HttpParserTest extends TestCase
+ "Server5: notServer\015\012" + "Server5: notServer\015\012"
+ "\015\012"); + "\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("GET", f0); assertEquals("GET", f0);
assertEquals("/", f1); assertEquals("/", f1);
@ -223,10 +223,10 @@ public class HttpParserTest extends TestCase
+ "0\015\012"); + "0\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
ByteArrayBuffer content=new ByteArrayBuffer(8192); ByteArrayBuffer content=new ByteArrayBuffer(8192);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer,content}); SimpleBuffers buffers=new SimpleBuffers(buffer,content);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), content.capacity()); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("GET", f0); assertEquals("GET", f0);
assertEquals("/chunk", f1); assertEquals("/chunk", f1);
@ -263,10 +263,10 @@ public class HttpParserTest extends TestCase
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
ByteArrayBuffer content=new ByteArrayBuffer(8192); ByteArrayBuffer content=new ByteArrayBuffer(8192);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer,content}); SimpleBuffers buffers=new SimpleBuffers(buffer,content);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), content.capacity()); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("GET", f0); assertEquals("GET", f0);
assertEquals("/mp", f1); assertEquals("/mp", f1);
@ -341,10 +341,10 @@ public class HttpParserTest extends TestCase
{ {
ByteArrayBuffer buffer= new ByteArrayBuffer(tests[t]); ByteArrayBuffer buffer= new ByteArrayBuffer(tests[t]);
ByteArrayBuffer content=new ByteArrayBuffer(8192); ByteArrayBuffer content=new ByteArrayBuffer(8192);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer,content}); SimpleBuffers buffers=new SimpleBuffers(buffer,content);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), content.capacity()); HttpParser parser= new HttpParser(buffers,io, handler);
io.setInput(http); io.setInput(http);
@ -396,10 +396,10 @@ public class HttpParserTest extends TestCase
+ "\015\012" + "\015\012"
+ "0123456789\015\012"); + "0123456789\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("HTTP/1.1", f0); assertEquals("HTTP/1.1", f0);
assertEquals("200", f1); assertEquals("200", f1);
@ -418,10 +418,10 @@ public class HttpParserTest extends TestCase
+ "Connection: close\015\012" + "Connection: close\015\012"
+ "\015\012"); + "\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("HTTP/1.1", f0); assertEquals("HTTP/1.1", f0);
assertEquals("304", f1); assertEquals("304", f1);
@ -444,10 +444,10 @@ public class HttpParserTest extends TestCase
+ "\015\012" + "\015\012"
+ "0123456789\015\012"); + "0123456789\015\012");
ByteArrayBuffer buffer= new ByteArrayBuffer(4096); ByteArrayBuffer buffer= new ByteArrayBuffer(4096);
SimpleBuffers buffers=new SimpleBuffers(new Buffer[]{buffer}); SimpleBuffers buffers=new SimpleBuffers(buffer,null);
Handler handler = new Handler(); Handler handler = new Handler();
HttpParser parser= new HttpParser(buffers,io, handler, buffer.capacity(), 0); HttpParser parser= new HttpParser(buffers,io, handler);
parser.parse(); parser.parse();
assertEquals("HTTP/1.1", f0); assertEquals("HTTP/1.1", f0);
assertEquals("204", f1); assertEquals("204", f1);

View File

@ -1,191 +0,0 @@
// ========================================================================
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.io;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
/* ------------------------------------------------------------ */
/** Abstract Buffer pool.
* simple unbounded pool of buffers for header, request and response sizes.
*
*/
public abstract class AbstractBuffers extends AbstractLifeCycle implements Buffers
{
private int _headerBufferSize=6*1024;
private int _requestBufferSize=8*1024;
private int _responseBufferSize=12*1024;
final static private int __HEADER=0;
final static private int __REQUEST=1;
final static private int __RESPONSE=2;
final static private int __OTHER=3;
final private int[] _pool={2,1,1,1};
private final ThreadLocal _buffers=new ThreadLocal()
{
protected Object initialValue()
{
return new ThreadBuffers(_pool[__HEADER],_pool[__REQUEST],_pool[__RESPONSE],_pool[__OTHER]);
}
};
public AbstractBuffers()
{
super();
}
public Buffer getBuffer(final int size )
{
final int set = (size==_headerBufferSize)?__HEADER
:(size==_responseBufferSize)?__RESPONSE
:(size==_requestBufferSize)?__REQUEST:__OTHER;
final ThreadBuffers thread_buffers = (ThreadBuffers)_buffers.get();
final Buffer[] buffers=thread_buffers._buffers[set];
for (int i=0;i<buffers.length;i++)
{
final Buffer b=buffers[i];
if (b!=null && b.capacity()==size)
{
buffers[i]=null;
return b;
}
}
return newBuffer(size);
}
public void returnBuffer( Buffer buffer )
{
buffer.clear();
if (buffer.isVolatile() || buffer.isImmutable())
return;
int size=buffer.capacity();
final int set = (size==_headerBufferSize)?__HEADER
:(size==_responseBufferSize)?__RESPONSE
:(size==_requestBufferSize)?__REQUEST:__OTHER;
final ThreadBuffers thread_buffers = (ThreadBuffers)_buffers.get();
final Buffer[] buffers=thread_buffers._buffers[set];
for (int i=0;i<buffers.length;i++)
{
if (buffers[i]==null)
{
buffers[i]=buffer;
return;
}
}
}
protected void doStart()
throws Exception
{
super.doStart();
if (_headerBufferSize==_requestBufferSize && _headerBufferSize==_responseBufferSize)
{
_pool[__HEADER]+=_pool[__REQUEST]+_pool[__RESPONSE];
_pool[__REQUEST]=0;
_pool[__RESPONSE]=0;
}
else if (_headerBufferSize==_requestBufferSize)
{
_pool[__HEADER]+=_pool[__REQUEST];
_pool[__REQUEST]=0;
}
else if (_headerBufferSize==_responseBufferSize)
{
_pool[__HEADER]+=_pool[__RESPONSE];
_pool[__RESPONSE]=0;
}
else if (_requestBufferSize==_responseBufferSize)
{
_pool[__RESPONSE]+=_pool[__REQUEST];
_pool[__REQUEST]=0;
}
}
/**
* @return Returns the headerBufferSize.
*/
public int getHeaderBufferSize()
{
return _headerBufferSize;
}
/**
* @param headerBufferSize The headerBufferSize to set.
*/
public void setHeaderBufferSize( int headerBufferSize )
{
if (isStarted())
throw new IllegalStateException();
_headerBufferSize = headerBufferSize;
}
/**
* @return Returns the requestBufferSize.
*/
public int getRequestBufferSize()
{
return _requestBufferSize;
}
/**
* @param requestBufferSize The requestBufferSize to set.
*/
public void setRequestBufferSize( int requestBufferSize )
{
if (isStarted())
throw new IllegalStateException();
_requestBufferSize = requestBufferSize;
}
/**
* @return Returns the responseBufferSize.
*/
public int getResponseBufferSize()
{
return _responseBufferSize;
}
/**
* @param responseBufferSize The responseBufferSize to set.
*/
public void setResponseBufferSize( int responseBufferSize )
{
if (isStarted())
throw new IllegalStateException();
_responseBufferSize = responseBufferSize;
}
protected abstract Buffer newBuffer( int size );
protected static class ThreadBuffers
{
final Buffer[][] _buffers;
ThreadBuffers(int headers,int requests,int responses,int others)
{
_buffers = new Buffer[4][];
_buffers[__HEADER]=new Buffer[headers];
_buffers[__REQUEST]=new Buffer[requests];
_buffers[__RESPONSE]=new Buffer[responses];
_buffers[__OTHER]=new Buffer[others];
}
}
}

View File

@ -20,11 +20,12 @@ package org.eclipse.jetty.io;
* of specific types of buffers (eg NIO). The concept of big and little buffers * of specific types of buffers (eg NIO). The concept of big and little buffers
* is supported, but these terms have no absolute meaning and must be determined by context. * is supported, but these terms have no absolute meaning and must be determined by context.
* *
*
*
*/ */
public interface Buffers public interface Buffers
{ {
public Buffer getBuffer(int size); Buffer getHeader();
public void returnBuffer(Buffer buffer); Buffer getBuffer();
Buffer getBuffer(int size);
void returnBuffer(Buffer buffer);
} }

View File

@ -21,54 +21,92 @@ package org.eclipse.jetty.io;
*/ */
public class SimpleBuffers implements Buffers public class SimpleBuffers implements Buffers
{ {
Buffer[] _buffers; final Buffer _header;
final Buffer _buffer;
boolean _headerOut;
boolean _bufferOut;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* *
*/ */
public SimpleBuffers(Buffer[] buffers) public SimpleBuffers(Buffer header, Buffer buffer)
{ {
_buffers=buffers; _header=header;
_buffer=buffer;
}
/* ------------------------------------------------------------ */
public Buffer getBuffer()
{
synchronized(this)
{
if (_buffer!=null && !_bufferOut)
{
_bufferOut=true;
return _buffer;
}
if (_buffer!=null && _header!=null && _header.capacity()==_buffer.capacity() && !_headerOut)
{
_headerOut=true;
return _header;
}
if (_buffer!=null)
return new ByteArrayBuffer(_buffer.capacity());
return new ByteArrayBuffer(4096);
}
}
/* ------------------------------------------------------------ */
public Buffer getHeader()
{
synchronized(this)
{
if (_header!=null && !_headerOut)
{
_headerOut=true;
return _header;
}
if (_buffer!=null && _header!=null && _header.capacity()==_buffer.capacity() && !_bufferOut)
{
_bufferOut=true;
return _buffer;
}
if (_header!=null)
return new ByteArrayBuffer(_header.capacity());
return new ByteArrayBuffer(4096);
}
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/*
* @see org.eclipse.io.Buffers#getBuffer(boolean)
*/
public Buffer getBuffer(int size) public Buffer getBuffer(int size)
{ {
if (_buffers!=null) synchronized(this)
{ {
for (int i=0;i<_buffers.length;i++) if (_header!=null && _header.capacity()==size)
{ return getHeader();
if (_buffers[i]!=null && _buffers[i].capacity()==size) if (_buffer!=null && _buffer.capacity()==size)
{ return getBuffer();
Buffer b=_buffers[i]; return null;
_buffers[i]=null;
return b;
}
}
} }
return new ByteArrayBuffer(size);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/*
* @see org.eclipse.io.Buffers#returnBuffer(org.eclipse.io.Buffer)
*/
public void returnBuffer(Buffer buffer) public void returnBuffer(Buffer buffer)
{ {
buffer.clear(); synchronized(this)
if (_buffers!=null)
{ {
for (int i=0;i<_buffers.length;i++) buffer.clear();
{ if (buffer==_header)
if (_buffers[i]==null) _headerOut=false;
_buffers[i]=buffer; if (buffer==_buffer)
} _bufferOut=false;
} }
} }
} }

View File

@ -0,0 +1,157 @@
// ========================================================================
// Copyright (c) 2004-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.io;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
/* ------------------------------------------------------------ */
/** Abstract Buffer pool.
* simple unbounded pool of buffers for header, request and response sizes.
*
*/
public abstract class ThreadLocalBuffers implements Buffers
{
private int _bufferSize=12*1024;
private int _headerSize=6*1024;
private final ThreadLocal<ThreadBuffers> _buffers=new ThreadLocal<ThreadBuffers>()
{
protected ThreadBuffers initialValue()
{
return new ThreadBuffers();
}
};
public Buffer getBuffer()
{
ThreadBuffers buffers = (ThreadBuffers)_buffers.get();
if (buffers._buffer!=null)
{
Buffer b=buffers._buffer;
buffers._buffer=null;
return b;
}
if (buffers._other!=null && buffers._other.capacity()==_bufferSize)
{
Buffer b=buffers._other;
buffers._other=null;
return b;
}
return newBuffer(_bufferSize);
}
public Buffer getHeader()
{
ThreadBuffers buffers = (ThreadBuffers)_buffers.get();
if (buffers._header!=null)
{
Buffer b=buffers._header;
buffers._header=null;
return b;
}
if (buffers._other!=null && buffers._other.capacity()==_headerSize)
{
Buffer b=buffers._other;
buffers._other=null;
return b;
}
return newHeader(_headerSize);
}
public Buffer getBuffer(int size)
{
ThreadBuffers buffers = (ThreadBuffers)_buffers.get();
if (buffers._other!=null && buffers._other.capacity()==size)
{
Buffer b=buffers._other;
buffers._other=null;
return b;
}
return newBuffer(size);
}
public void returnBuffer(Buffer buffer)
{
buffer.clear();
if (buffer.isVolatile() || buffer.isImmutable())
return;
int size=buffer.capacity();
ThreadBuffers buffers = (ThreadBuffers)_buffers.get();
if (size==_bufferSize && buffers._buffer==null)
{
buffers._buffer=buffer;
}
else if (size==_headerSize && buffers._header==null)
{
buffers._header=buffer;
}
else
{
buffers._other=buffer;
}
}
/**
* @return Returns the buffer size in bytes.
*/
public int getBufferSize()
{
return _bufferSize;
}
/**
* @return Returns the header size in bytes.
*/
public int getHeaderSize()
{
return _headerSize;
}
protected abstract Buffer newBuffer(int size);
protected abstract Buffer newHeader(int size);
/**
* @param size The buffer size in bytes
*/
public void setBufferSize( int size )
{
_bufferSize = size;
}
/**
* @param size The header size in bytes
*/
public void setHeaderSize( int size )
{
_headerSize = size;
}
protected static class ThreadBuffers
{
Buffer _buffer;
Buffer _header;
Buffer _other;
}
}

View File

@ -23,7 +23,6 @@ import org.eclipse.jetty.io.AsyncEndPoint;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.HttpException;
import org.eclipse.jetty.io.nio.SelectorManager.SelectSet; import org.eclipse.jetty.io.nio.SelectorManager.SelectSet;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.thread.Timeout; import org.eclipse.jetty.util.thread.Timeout;
@ -432,9 +431,10 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements Runnable,
try{close();} try{close();}
catch(IOException e2){Log.ignore(e2);} catch(IOException e2){Log.ignore(e2);}
} }
catch (HttpException e) catch (IOException e)
{ {
Log.debug("BAD", e); Log.warn(e.toString());
Log.debug(e);
try{close();} try{close();}
catch(IOException e2){Log.ignore(e2);} catch(IOException e2){Log.ignore(e2);}
} }

View File

@ -20,13 +20,13 @@ import java.util.concurrent.atomic.AtomicLong;
import junit.framework.TestCase; import junit.framework.TestCase;
public class AbstractBuffersTest public class ThreadLocalBuffersTest
extends TestCase extends TestCase
{ {
public boolean _stress = Boolean.getBoolean("STRESS"); public boolean _stress = Boolean.getBoolean("STRESS");
private int _headerBufferSize = 6 * 1024; private int _headerBufferSize = 6 * 1024;
InnerAbstractBuffers buffers; InnerBuffers httpBuffers;
List<Thread> threadList = new ArrayList<Thread>(); List<Thread> threadList = new ArrayList<Thread>();
@ -63,7 +63,7 @@ public class AbstractBuffersTest
{ {
threadList.clear(); threadList.clear();
buffersRetrieved = new AtomicLong( 0 ); buffersRetrieved = new AtomicLong( 0 );
buffers = new InnerAbstractBuffers(); httpBuffers = new InnerBuffers();
for ( int i = 0; i < numThreads; ++i ) for ( int i = 0; i < numThreads; ++i )
{ {
@ -115,11 +115,16 @@ public class AbstractBuffersTest
} }
class InnerAbstractBuffers class InnerBuffers extends ThreadLocalBuffers
extends AbstractBuffers
{ {
@Override
protected Buffer newBuffer(int size)
{
return new ByteArrayBuffer( size );
}
public Buffer newBuffer( int size ) @Override
protected Buffer newHeader(int size)
{ {
return new ByteArrayBuffer( size ); return new ByteArrayBuffer( size );
} }
@ -153,7 +158,7 @@ public class AbstractBuffersTest
if ( runTest ) if ( runTest )
{ {
Buffer buf = buffers.getBuffer( _headerBufferSize ); Buffer buf = httpBuffers.getHeader();
buffersRetrieved.getAndIncrement(); buffersRetrieved.getAndIncrement();
@ -162,7 +167,7 @@ public class AbstractBuffersTest
// sleep( threadWaitTime ); // sleep( threadWaitTime );
buffers.returnBuffer( buf ); httpBuffers.returnBuffer(buf);
} }
else else
{ {

View File

@ -20,10 +20,12 @@ import java.net.UnknownHostException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import org.eclipse.jetty.http.HttpBuffers;
import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeaders; import org.eclipse.jetty.http.HttpHeaders;
import org.eclipse.jetty.http.HttpSchemes; import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.io.AbstractBuffers; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.component.LifeCycle;
@ -43,7 +45,7 @@ import org.eclipse.jetty.util.thread.ThreadPool;
* *
* *
*/ */
public abstract class AbstractConnector extends AbstractBuffers implements Connector public abstract class AbstractConnector extends HttpBuffers implements Connector
{ {
private String _name; private String _name;
@ -98,6 +100,37 @@ public abstract class AbstractConnector extends AbstractBuffers implements Conne
{ {
} }
/* ------------------------------------------------------------------------------- */
public final Buffer newBuffer(int size)
{
// TODO remove once no overrides established
return null;
}
/* ------------------------------------------------------------------------------- */
public Buffer newRequestBuffer(int size)
{
return new ByteArrayBuffer(size);
}
/* ------------------------------------------------------------------------------- */
public Buffer newRequestHeader(int size)
{
return new ByteArrayBuffer(size);
}
/* ------------------------------------------------------------------------------- */
public Buffer newResponseBuffer(int size)
{
return new ByteArrayBuffer(size);
}
/* ------------------------------------------------------------------------------- */
public Buffer newResponseHeader(int size)
{
return new ByteArrayBuffer(size);
}
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
/* /*
*/ */

View File

@ -33,7 +33,7 @@ import org.eclipse.jetty.util.thread.ThreadPool;
* *
* *
*/ */
public interface Connector extends LifeCycle, Buffers public interface Connector extends LifeCycle
{ {
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
@ -59,17 +59,42 @@ public interface Connector extends LifeCycle, Buffers
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* @return Returns the headerBufferSize. * @return Returns the request header buffer size in bytes.
*/ */
int getHeaderBufferSize(); int getRequestHeaderSize();
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* Set the size of the buffer to be used for request and response headers. * Set the size of the buffer to be used for request headers.
* An idle connection will at most have one buffer of this size allocated. * @param size The size in bytes.
* @param headerBufferSize The headerBufferSize to set.
*/ */
void setHeaderBufferSize(int headerBufferSize); void setRequestHeaderSize(int size);
/* ------------------------------------------------------------ */
/**
* @return Returns the response header buffer size in bytes.
*/
int getResponseHeaderSize();
/* ------------------------------------------------------------ */
/**
* Set the size of the buffer to be used for request headers.
* @param size The size in bytes.
*/
void setResponseHeaderSize(int size);
/* ------------------------------------------------------------ */
/**
* @return factory for request buffers
*/
Buffers getRequestBuffers();
/* ------------------------------------------------------------ */
/**
* @return factory for response buffers
*/
Buffers getResponseBuffers();
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */

View File

@ -25,7 +25,9 @@ import org.eclipse.jetty.continuation.ContinuationThrowable;
import org.eclipse.jetty.http.AbstractGenerator; import org.eclipse.jetty.http.AbstractGenerator;
import org.eclipse.jetty.http.EncodedHttpURI; import org.eclipse.jetty.http.EncodedHttpURI;
import org.eclipse.jetty.http.Generator; import org.eclipse.jetty.http.Generator;
import org.eclipse.jetty.http.HttpBuffers;
import org.eclipse.jetty.http.HttpContent; import org.eclipse.jetty.http.HttpContent;
import org.eclipse.jetty.http.HttpException;
import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpGenerator; import org.eclipse.jetty.http.HttpGenerator;
import org.eclipse.jetty.http.HttpHeaderValues; import org.eclipse.jetty.http.HttpHeaderValues;
@ -41,7 +43,6 @@ import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.HttpException;
import org.eclipse.jetty.io.BufferCache.CachedBuffer; import org.eclipse.jetty.io.BufferCache.CachedBuffer;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint; import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.util.QuotedStringTokenizer; import org.eclipse.jetty.util.QuotedStringTokenizer;
@ -128,12 +129,13 @@ public class HttpConnection implements Connection
_uri = URIUtil.__CHARSET==StringUtil.__UTF8?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET); _uri = URIUtil.__CHARSET==StringUtil.__UTF8?new HttpURI():new EncodedHttpURI(URIUtil.__CHARSET);
_connector = connector; _connector = connector;
_endp = endpoint; _endp = endpoint;
_parser = new HttpParser(_connector, endpoint, new RequestHandler(), _connector.getHeaderBufferSize(), _connector.getRequestBufferSize()); HttpBuffers ab = (HttpBuffers)_connector;
_parser = new HttpParser(ab.getRequestBuffers(), endpoint, new RequestHandler());
_requestFields = new HttpFields(); _requestFields = new HttpFields();
_responseFields = new HttpFields(); _responseFields = new HttpFields();
_request = new Request(this); _request = new Request(this);
_response = new Response(this); _response = new Response(this);
_generator = new HttpGenerator(_connector, _endp, _connector.getHeaderBufferSize(), _connector.getResponseBufferSize()); _generator = new HttpGenerator(ab.getResponseBuffers(), _endp);
_generator.setSendServerVersion(server.getSendServerVersion()); _generator.setSendServerVersion(server.getSendServerVersion());
_server = server; _server = server;
} }

View File

@ -149,12 +149,6 @@ public class LocalConnector extends AbstractConnector
return _out; return _out;
} }
/* ------------------------------------------------------------ */
public Buffer newBuffer(int size)
{
return new ByteArrayBuffer(size);
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
protected void accept(int acceptorID) throws IOException, InterruptedException protected void accept(int acceptorID) throws IOException, InterruptedException
{ {

View File

@ -21,11 +21,11 @@ import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import org.eclipse.jetty.http.HttpException;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer; import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.HttpException;
import org.eclipse.jetty.io.bio.SocketEndPoint; import org.eclipse.jetty.io.bio.SocketEndPoint;
import org.eclipse.jetty.server.AbstractConnector; import org.eclipse.jetty.server.AbstractConnector;
import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.server.HttpConnection;
@ -111,12 +111,6 @@ public class SocketConnector extends AbstractConnector
return new HttpConnection(this, endpoint, getServer()); return new HttpConnection(this, endpoint, getServer());
} }
/* ------------------------------------------------------------------------------- */
public Buffer newBuffer(int size)
{
return new ByteArrayBuffer(size);
}
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
public void customize(EndPoint endpoint, Request request) public void customize(EndPoint endpoint, Request request)
throws IOException throws IOException

View File

@ -45,9 +45,9 @@ import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpException;
import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.HttpException;
import org.eclipse.jetty.server.Dispatcher; import org.eclipse.jetty.server.Dispatcher;
import org.eclipse.jetty.server.DispatcherType; import org.eclipse.jetty.server.DispatcherType;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;

View File

@ -46,32 +46,44 @@ public abstract class AbstractNIOConnector extends AbstractConnector implements
{ {
_useDirectBuffers=direct; _useDirectBuffers=direct;
} }
/* ------------------------------------------------------------------------------- */
public Buffer newBuffer(int size)
{
// TODO
// Header buffers always byte array buffers (efficiency of random access)
// There are lots of things to consider here... DIRECT buffers are faster to
// send but more expensive to build and access! so we have choices to make...
// + headers are constructed bit by bit and parsed bit by bit, so INDiRECT looks
// good for them.
// + but will a gather write of an INDIRECT header with a DIRECT body be any good?
// this needs to be benchmarked.
// + Will it be possible to get a DIRECT header buffer just for the gather writes of
// content from file mapped buffers?
// + Are gather writes worth the effort? Maybe they will work well with two INDIRECT
// buffers being copied into a single kernel buffer?
//
Buffer buf = null;
if (size==getHeaderBufferSize())
buf= new IndirectNIOBuffer(size);
else
buf = _useDirectBuffers
?(NIOBuffer)new DirectNIOBuffer(size)
:(NIOBuffer)new IndirectNIOBuffer(size);
return buf;
}
// TODO
// Header buffers always byte array buffers (efficiency of random access)
// There are lots of things to consider here... DIRECT buffers are faster to
// send but more expensive to build and access! so we have choices to make...
// + headers are constructed bit by bit and parsed bit by bit, so INDiRECT looks
// good for them.
// + but will a gather write of an INDIRECT header with a DIRECT body be any good?
// this needs to be benchmarked.
// + Will it be possible to get a DIRECT header buffer just for the gather writes of
// content from file mapped buffers?
// + Are gather writes worth the effort? Maybe they will work well with two INDIRECT
// buffers being copied into a single kernel buffer?
/* ------------------------------------------------------------------------------- */
public Buffer newRequestBuffer(int size)
{
return _useDirectBuffers?new DirectNIOBuffer(size):new IndirectNIOBuffer(size);
}
/* ------------------------------------------------------------------------------- */
public Buffer newRequestHeader(int size)
{
return new IndirectNIOBuffer(size);
}
/* ------------------------------------------------------------------------------- */
public Buffer newResponseBuffer(int size)
{
return _useDirectBuffers?new DirectNIOBuffer(size):new IndirectNIOBuffer(size);
}
/* ------------------------------------------------------------------------------- */
public Buffer newResponseHeader(int size)
{
// TODO maybe can be direct?
return new IndirectNIOBuffer(size);
}
} }

View File

@ -20,9 +20,9 @@ import java.nio.channels.ByteChannel;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import org.eclipse.jetty.http.HttpException;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.HttpException;
import org.eclipse.jetty.io.nio.ChannelEndPoint; import org.eclipse.jetty.io.nio.ChannelEndPoint;
import org.eclipse.jetty.server.HttpConnection; import org.eclipse.jetty.server.HttpConnection;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;

View File

@ -44,8 +44,10 @@ import org.eclipse.jetty.http.HttpSchemes;
import org.eclipse.jetty.http.security.Password; import org.eclipse.jetty.http.security.Password;
import org.eclipse.jetty.http.ssl.SslSelectChannelEndPoint; import org.eclipse.jetty.http.ssl.SslSelectChannelEndPoint;
import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.ThreadLocalBuffers;
import org.eclipse.jetty.io.bio.SocketEndPoint; import org.eclipse.jetty.io.bio.SocketEndPoint;
import org.eclipse.jetty.io.nio.DirectNIOBuffer; import org.eclipse.jetty.io.nio.DirectNIOBuffer;
import org.eclipse.jetty.io.nio.IndirectNIOBuffer; import org.eclipse.jetty.io.nio.IndirectNIOBuffer;
@ -114,61 +116,8 @@ public class SslSelectChannelConnector extends SelectChannelConnector
private String _truststore; private String _truststore;
private String _truststoreType="JKS"; // type of the key store private String _truststoreType="JKS"; // type of the key store
private SSLContext _context; private SSLContext _context;
Buffers _sslBuffers;
private int _packetBufferSize;
private int _applicationBufferSize;
private ConcurrentLinkedQueue<Buffer> _packetBuffers = new ConcurrentLinkedQueue<Buffer>();
private ConcurrentLinkedQueue<Buffer> _applicationBuffers = new ConcurrentLinkedQueue<Buffer>();
/* ------------------------------------------------------------ */
/* (non-Javadoc)
* @see org.eclipse.jetty.io.AbstractBuffers#getBuffer(int)
*/
public Buffer getBuffer(int size)
{
// TODO why is this reimplemented?
Buffer buffer;
if (size==_applicationBufferSize)
{
buffer = _applicationBuffers.poll();
if (buffer==null)
buffer=new IndirectNIOBuffer(size);
}
else if (size==_packetBufferSize)
{
buffer = _packetBuffers.poll();
if (buffer==null)
buffer=getUseDirectBuffers()
?(NIOBuffer)new DirectNIOBuffer(size)
:(NIOBuffer)new IndirectNIOBuffer(size);
}
else
buffer=super.getBuffer(size);
return buffer;
}
/* ------------------------------------------------------------ */
/* (non-Javadoc)
* @see org.eclipse.jetty.io.AbstractBuffers#returnBuffer(org.eclipse.io.Buffer)
*/
public void returnBuffer(Buffer buffer)
{
buffer.clear();
int size=buffer.capacity();
ByteBuffer bbuf = ((NIOBuffer)buffer).getByteBuffer();
bbuf.position(0);
bbuf.limit(size);
if (size==_applicationBufferSize)
_applicationBuffers.add(buffer);
else if (size==_packetBufferSize)
_packetBuffers.add(buffer);
else
super.returnBuffer(buffer);
}
/** /**
* Return the chain of X509 certificates used to negotiate the SSL Session. * Return the chain of X509 certificates used to negotiate the SSL Session.
@ -528,7 +477,7 @@ public class SslSelectChannelConnector extends SelectChannelConnector
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException
{ {
return new SslSelectChannelEndPoint(this,channel,selectSet,key,createSSLEngine()); return new SslSelectChannelEndPoint(_sslBuffers,channel,selectSet,key,createSSLEngine());
} }
/* ------------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------------- */
@ -591,9 +540,29 @@ public class SslSelectChannelConnector extends SelectChannelConnector
SSLEngine engine=createSSLEngine(); SSLEngine engine=createSSLEngine();
SSLSession ssl_session=engine.getSession(); SSLSession ssl_session=engine.getSession();
setHeaderBufferSize(ssl_session.getApplicationBufferSize()); ThreadLocalBuffers buffers = new ThreadLocalBuffers()
setRequestBufferSize(ssl_session.getApplicationBufferSize()); {
setResponseBufferSize(ssl_session.getApplicationBufferSize()); @Override
protected Buffer newBuffer(int size)
{
// TODO indirect?
return new DirectNIOBuffer(size);
}
@Override
protected Buffer newHeader(int size)
{
// TODO indirect?
return new DirectNIOBuffer(size);
}
};
buffers.setBufferSize(ssl_session.getApplicationBufferSize());
buffers.setHeaderSize(ssl_session.getPacketBufferSize());
_sslBuffers=buffers;
if (getRequestHeaderSize()<ssl_session.getApplicationBufferSize())
setRequestHeaderSize(ssl_session.getApplicationBufferSize());
if (getRequestBufferSize()<ssl_session.getApplicationBufferSize())
setRequestBufferSize(ssl_session.getApplicationBufferSize());
super.doStart(); super.doStart();
} }

View File

@ -67,6 +67,8 @@ public class StressTest extends TestCase
c_connector.setAcceptors(4); c_connector.setAcceptors(4);
c_connector.setAcceptQueueSize(1000); c_connector.setAcceptQueueSize(1000);
//c_connector.setPort(8080);
_connector=c_connector; _connector=c_connector;
_connector.setMaxIdleTime(30000); _connector.setMaxIdleTime(30000);
@ -75,6 +77,8 @@ public class StressTest extends TestCase
_server.start(); _server.start();
_port=_connector.getLocalPort(); _port=_connector.getLocalPort();
_addr=Inet4Address.getLocalHost(); _addr=Inet4Address.getLocalHost();
//_addr=Inet4Address.getByName("10.10.1.16");
System.err.println("ADDR "+_addr+":"+_port);
for (Queue q:_latencies) for (Queue q:_latencies)
q.clear(); q.clear();

View File

@ -35,9 +35,9 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.continuation.ContinuationThrowable; import org.eclipse.jetty.continuation.ContinuationThrowable;
import org.eclipse.jetty.http.HttpException;
import org.eclipse.jetty.http.PathMap; import org.eclipse.jetty.http.PathMap;
import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.HttpException;
import org.eclipse.jetty.security.IdentityService; import org.eclipse.jetty.security.IdentityService;
import org.eclipse.jetty.security.SecurityHandler; import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.Dispatcher; import org.eclipse.jetty.server.Dispatcher;

View File

@ -54,7 +54,7 @@ public class Jetty6ContinuationTest extends ContinuationBase
public void testJetty6() throws Exception public void testJetty6() throws Exception
{ {
_filter.setInitParameter("debug","true"); _filter.setInitParameter("debug","true");
_filter.setInitParameter("faux","false"); //_filter.setInitParameter("faux","false");
_server.start(); _server.start();
_port=_connector.getLocalPort(); _port=_connector.getLocalPort();

View File

@ -154,7 +154,7 @@ public class HttpTester
Buffer bb=new ByteArrayBuffer(32*1024 + (_genContent!=null?_genContent.length:0)); Buffer bb=new ByteArrayBuffer(32*1024 + (_genContent!=null?_genContent.length:0));
Buffer sb=new ByteArrayBuffer(4*1024); Buffer sb=new ByteArrayBuffer(4*1024);
StringEndPoint endp = new StringEndPoint(_charset); StringEndPoint endp = new StringEndPoint(_charset);
HttpGenerator generator = new HttpGenerator(new SimpleBuffers(new Buffer[]{sb,bb}),endp, sb.capacity(), bb.capacity()); HttpGenerator generator = new HttpGenerator(new SimpleBuffers(sb,bb),endp);
if (_method!=null) if (_method!=null)
{ {