You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2006/10/26 22:37:41 UTC
svn commit: r468124 - in /tomcat/tc6.0.x/trunk/java/org/apache:
coyote/http11/ tomcat/util/net/
Author: fhanik
Date: Thu Oct 26 13:37:40 2006
New Revision: 468124
URL: http://svn.apache.org/viewvc?view=rev&rev=468124
Log:
Make sure the socket buffer is not bigger than anticipated header size
Reuse the key attachment objects properly
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioChannel.java
tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?view=diff&rev=468124&r1=468123&r2=468124
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Thu Oct 26 13:37:40 2006
@@ -83,7 +83,7 @@
// ----------------------------------------------------------- Constructors
- public Http11NioProcessor(int rxBufSize, int txBufSize, NioEndpoint endpoint) {
+ public Http11NioProcessor(int rxBufSize, int txBufSize, int maxHttpHeaderSize, NioEndpoint endpoint) {
this.endpoint = endpoint;
@@ -95,12 +95,12 @@
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);
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java?view=diff&rev=468124&r1=468123&r2=468124
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProtocol.java Thu Oct 26 13:37:40 2006
@@ -655,8 +655,9 @@
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);
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java?view=diff&rev=468124&r1=468123&r2=468124
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalNioOutputBuffer.java Thu Oct 26 13:37:40 2006
@@ -605,7 +605,7 @@
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);
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java?view=diff&rev=468124&r1=468123&r2=468124
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/InternalOutputBuffer.java Thu Oct 26 13:37:40 2006
@@ -61,6 +61,7 @@
public InternalOutputBuffer(Response response, int headerBufferSize) {
this.response = response;
+
headers = response.getMimeHeaders();
headerBuffer = new byte[headerBufferSize];
Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioChannel.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioChannel.java?view=diff&rev=468124&r1=468123&r2=468124
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioChannel.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioChannel.java Thu Oct 26 13:37:40 2006
@@ -26,6 +26,7 @@
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;
/**
*
@@ -82,7 +83,7 @@
*/
public void close() throws IOException {
getIOChannel().socket().close();
- sc.close();
+ getIOChannel().close();
}
public void close(boolean force) throws IOException {
@@ -122,7 +123,14 @@
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
*
Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?view=diff&rev=468124&r1=468123&r2=468124
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Thu Oct 26 13:37:40 2006
@@ -165,16 +165,7 @@
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
@@ -1037,6 +1028,10 @@
}
}//end if
}//run
+
+ public String toString() {
+ return super.toString()+"[intOps="+this.interestOps+"]";
+ }
}
/**
* Poller class.
@@ -1159,7 +1154,6 @@
* hands them off to an appropriate processor.
*/
public void run() {
-
// Loop until we receive a shutdown command
while (running) {
// Loop if endpoint is paused
@@ -1178,8 +1172,8 @@
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
@@ -1456,18 +1450,22 @@
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);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org