Author: markt
Date: Mon Feb 27 11:14:28 2012
New Revision: 1294109
URL: http://svn.apache.org/viewvc?rev=1294109&view=rev
Log:
Don't read/write more data than the internal buffers can handle
Modified:
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java
Modified:
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java?rev=1294109&r1=1294108&r2=1294109&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java
(original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeNioProcessor.java
Mon Feb 27 11:14:28 2012
@@ -35,6 +35,8 @@ public class UpgradeNioProcessor extends
private final NioChannel nioChannel;
private final NioSelectorPool pool;
+ private final int maxRead;
+ private final int maxWrite;
public UpgradeNioProcessor(SocketWrapper<NioChannel> wrapper,
UpgradeInbound upgradeInbound, NioSelectorPool pool) {
@@ -42,6 +44,8 @@ public class UpgradeNioProcessor extends
this.nioChannel = wrapper.getSocket();
this.pool = pool;
+ this.maxRead = nioChannel.getBufHandler().getReadBuffer().capacity();
+ this.maxWrite = nioChannel.getBufHandler().getWriteBuffer().capacity();
}
@@ -82,7 +86,11 @@ public class UpgradeNioProcessor extends
@Override
public void write(byte[]b, int off, int len) throws IOException {
- writeToSocket(b, off, len);
+ int written = 0;
+ while (len - written > maxWrite) {
+ written += writeToSocket(b, off + written, maxWrite);
+ }
+ writeToSocket(b, off + written, len - written);
}
/*
@@ -100,7 +108,12 @@ public class UpgradeNioProcessor extends
@Override
public int read(byte[] bytes, int off, int len) throws IOException {
- return readSocket(true, bytes, off, len);
+ if (len > maxRead) {
+ return readSocket(true, bytes, off, maxRead);
+ } else {
+ return readSocket(true, bytes, off, len);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]