// ----------------------------------------------------------- Constructors
- public Http11NioProcessor(int rxBufSize, int txBufSize, NioEndpoint endpoint) {
+ public Http11NioProcessor(int rxBufSize, int txBufSize, int maxHttpHeaderSize, NioEndpoint endpoint) {
this.endpoint = endpoint;
readTimeout = timeout;
//readTimeout = -1;
}
- inputBuffer = new InternalNioInputBuffer(request, rxBufSize,readTimeout);
+ inputBuffer = new InternalNioInputBuffer(request, maxHttpHeaderSize,readTimeout);
request.setInputBuffer(inputBuffer);
response = new Response();
response.setHook(this);
- outputBuffer = new InternalNioOutputBuffer(response, txBufSize,readTimeout);
+ outputBuffer = new InternalNioOutputBuffer(response, maxHttpHeaderSize,readTimeout);
response.setOutputBuffer(outputBuffer);
request.setResponse(response);
public Http11NioProcessor createProcessor() {
Http11NioProcessor processor = new Http11NioProcessor(
- Math.max(proto.maxHttpHeaderSize,proto.ep.getSocketProperties().getRxBufSize()),
- Math.max(proto.maxHttpHeaderSize,proto.ep.getSocketProperties().getRxBufSize()),
+ proto.ep.getSocketProperties().getRxBufSize(),
+ proto.ep.getSocketProperties().getTxBufSize(),
+ proto.maxHttpHeaderSize,
proto.ep);
processor.setAdapter(proto.adapter);
processor.setMaxKeepAliveRequests(proto.maxKeepAliveRequests);
int total = 0;
private void addToBB(byte[] buf, int offset, int length) throws IOException {
- if (socket.getBufHandler().getWriteBuffer().remaining() <= length) {
+ if (socket.getBufHandler().getWriteBuffer().remaining() < length) {
flushBuffer();
}
socket.getBufHandler().getWriteBuffer().put(buf, offset, length);
public InternalOutputBuffer(Response response, int headerBufferSize) {
this.response = response;
+
headers = response.getMimeHeaders();
headerBuffer = new byte[headerBufferSize];
import org.apache.tomcat.util.net.NioEndpoint.Poller;
import org.apache.tomcat.util.net.SecureNioChannel.ApplicationBufferHandler;
import java.nio.channels.Selector;
+import java.nio.channels.SelectionKey;
/**
*
*/
public void close() throws IOException {
getIOChannel().socket().close();
- sc.close();
+ getIOChannel().close();
}
public void close(boolean force) throws IOException {
return sc.read(dst);
}
-
+ public Object getAttachment(boolean remove) {
+ Poller pol = getPoller();
+ Selector sel = pol!=null?pol.getSelector():null;
+ SelectionKey key = sel!=null?getIOChannel().keyFor(sel):null;
+ Object att = key!=null?key.attachment():null;
+ if (key != null && att != null && remove ) key.attach(null);
+ return att;
+ }
/**
* getBufHandler
*
protected ConcurrentLinkedQueue<NioChannel> nioChannels = new ConcurrentLinkedQueue<NioChannel>() {
protected AtomicInteger size = new AtomicInteger(0);
protected AtomicInteger bytes = new AtomicInteger(0);
- public boolean offer(NioChannel socket) {
- Poller pol = socket.getPoller();
- Selector sel = pol!=null?pol.getSelector():null;
- SelectionKey key = sel!=null?socket.getIOChannel().keyFor(sel):null;
- KeyAttachment att = key!=null?(KeyAttachment)key.attachment():null;
- if ( att!=null ) {
- att.reset();
- keyCache.offer(att);
- }
- if ( key!=null ) key.attach(null);
+ public boolean offer(NioChannel socket, KeyAttachment att) {
boolean offer = socketProperties.getBufferPool()==-1?true:size.get()<socketProperties.getBufferPool();
offer = offer && (socketProperties.getBufferPoolSize()==-1?true:(bytes.get()+socket.getBufferSize())<socketProperties.getBufferPoolSize());
//avoid over growing our cache or add after we have stopped
}
}//end if
}//run
+
+ public String toString() {
+ return super.toString()+"[intOps="+this.interestOps+"]";
+ }
}
/**
* Poller class.
* hands them off to an appropriate processor.
*/
public void run() {
-
// Loop until we receive a shutdown command
while (running) {
// Loop if endpoint is paused
int keyCount = 0;
try {
- wakeupCounter.set(0);
keyCount = selector.select(selectorTimeout);
+ wakeupCounter.set(0);
if ( close ) { selector.close(); return; }
} catch ( NullPointerException x ) {
//sun bug 5076772 on windows JDK 1.5
if ((status != null) && (handler.event(socket, status) == Handler.SocketState.CLOSED)) {
// Close socket and pool
try {
+ KeyAttachment att = (KeyAttachment)socket.getAttachment(true);
try {socket.close();}catch (Exception ignore){}
if ( socket.isOpen() ) socket.close(true);
nioChannels.offer(socket);
+ if ( att!=null ) keyCache.offer(att);
}catch ( Exception x ) {
log.error("",x);
}
} else if ((status == null) && (handler.process(socket) == Handler.SocketState.CLOSED)) {
// Close socket and pool
try {
+ KeyAttachment att = (KeyAttachment)socket.getAttachment(true);
try {socket.close();}catch (Exception ignore){}
if ( socket.isOpen() ) socket.close(true);
nioChannels.offer(socket);
+ if ( att!=null ) keyCache.offer(att);
}catch ( Exception x ) {
log.error("",x);
}