You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/01/15 10:20:54 UTC
svn commit: r1652000 - in /tomcat/trunk/java/org/apache/coyote/http11:
InternalAprInputBuffer.java InternalNioInputBuffer.java
Author: markt
Date: Thu Jan 15 09:20:53 2015
New Revision: 1652000
URL: http://svn.apache.org/r1652000
Log:
APR:
- Simplify.
- Correct test for exceeded the max header size.
NIO
- Use read method from SocketWrapper
Modified:
tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java?rev=1652000&r1=1651999&r2=1652000&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalAprInputBuffer.java Thu Jan 15 09:20:53 2015
@@ -91,10 +91,8 @@ public class InternalAprInputBuffer exte
@Override
protected boolean fill(boolean block) throws IOException {
- int nRead = 0;
-
if (parsingHeader) {
- if (lastValid == buf.length) {
+ if (lastValid > headerBufferSize) {
throw new IllegalArgumentException
(sm.getString("iib.requestheadertoolarge.error"));
}
@@ -102,7 +100,7 @@ public class InternalAprInputBuffer exte
lastValid = pos = end;
}
- nRead = wrapper.read(block, buf, pos, buf.length - pos);
+ int nRead = wrapper.read(block, buf, pos, buf.length - pos);
if (nRead > 0) {
lastValid = pos + nRead;
return true;
Modified: tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java?rev=1652000&r1=1651999&r2=1652000&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/InternalNioInputBuffer.java Thu Jan 15 09:20:53 2015
@@ -18,8 +18,6 @@ package org.apache.coyote.http11;
import java.io.EOFException;
import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.Selector;
import org.apache.coyote.InputBuffer;
import org.apache.coyote.Request;
@@ -28,8 +26,6 @@ import org.apache.juli.logging.LogFactor
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.net.AbstractEndpoint;
import org.apache.tomcat.util.net.NioChannel;
-import org.apache.tomcat.util.net.NioEndpoint;
-import org.apache.tomcat.util.net.NioSelectorPool;
import org.apache.tomcat.util.net.SocketWrapperBase;
/**
@@ -41,8 +37,8 @@ public class InternalNioInputBuffer exte
private static final Log log =
LogFactory.getLog(InternalNioInputBuffer.class);
- // ----------------------------------------------------------- Constructors
+ // ----------------------------------------------------------- Constructors
/**
* Alternate constructor.
@@ -52,15 +48,10 @@ public class InternalNioInputBuffer exte
inputStreamInputBuffer = new SocketInputBuffer();
}
- /**
- * Underlying socket.
- */
- private NioChannel socket;
- /**
- * Selector pool, for blocking reads and blocking writes
- */
- private NioSelectorPool pool;
+ // ----------------------------------------------------- Instance Variables
+
+ private SocketWrapperBase<NioChannel> wrapper;
// --------------------------------------------------------- Public Methods
@@ -71,8 +62,8 @@ public class InternalNioInputBuffer exte
*/
@Override
public void recycle() {
+ wrapper = null;
super.recycle();
- socket = null;
}
// ------------------------------------------------------ Protected Methods
@@ -87,25 +78,18 @@ public class InternalNioInputBuffer exte
protected void init(SocketWrapperBase<NioChannel> socketWrapper,
AbstractEndpoint<NioChannel> endpoint) throws IOException {
- socket = socketWrapper.getSocket();
- if (socket == null) {
- // Socket has been closed in another thread
- throw new IOException(sm.getString("iib.socketClosed"));
- }
- socketReadBufferSize =
- socket.getBufHandler().getReadBuffer().capacity();
+ wrapper = socketWrapper;
- int bufLength = headerBufferSize + socketReadBufferSize;
+ int bufLength = Math.max(headerBufferSize, 8192);
if (buf == null || buf.length < bufLength) {
buf = new byte[bufLength];
}
-
- pool = ((NioEndpoint)endpoint).getSelectorPool();
}
@Override
protected boolean fill(boolean block) throws IOException, EOFException {
+
if (parsingHeader) {
if (lastValid > headerBufferSize) {
throw new IllegalArgumentException
@@ -114,44 +98,14 @@ public class InternalNioInputBuffer exte
} else {
lastValid = pos = end;
}
- int nRead = 0;
- ByteBuffer readBuffer = socket.getBufHandler().getReadBuffer();
- readBuffer.clear();
- if ( block ) {
- Selector selector = null;
- try {
- selector = pool.get();
- } catch ( IOException x ) {
- // Ignore
- }
- try {
- NioEndpoint.NioSocketWrapper att =
- (NioEndpoint.NioSocketWrapper) socket.getAttachment();
- if (att == null) {
- throw new IOException("Key must be cancelled.");
- }
- nRead = pool.read(readBuffer,
- socket, selector,
- socket.getIOChannel().socket().getSoTimeout());
- } catch ( EOFException eof ) {
- nRead = -1;
- } finally {
- if ( selector != null ) pool.put(selector);
- }
- } else {
- nRead = socket.read(readBuffer);
- }
+
+ int nRead = wrapper.read(block, buf, pos, buf.length - pos);
if (nRead > 0) {
- readBuffer.flip();
- readBuffer.limit(nRead);
- expand(nRead + pos);
- readBuffer.get(buf, pos, nRead);
lastValid = pos + nRead;
- } else if (nRead == -1) {
- //return false;
- throw new EOFException(sm.getString("iib.eof.error"));
+ return true;
}
- return nRead > 0;
+
+ return false;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org