tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1637940 - in /tomcat/trunk/java/org/apache: coyote/http11/upgrade/ tomcat/util/net/
Date Mon, 10 Nov 2014 16:47:56 GMT
Author: markt
Date: Mon Nov 10 16:47:56 2014
New Revision: 1637940

URL: http://svn.apache.org/r1637940
Log:
Add a standard method for returning input to the SocketWrapper.
Use this to make the code consistent between upgrade processor
implementations.

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprProcessor.java
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2Processor.java
    tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioProcessor.java
    tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
    tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprProcessor.java?rev=1637940&r1=1637939&r2=1637940&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/AprProcessor.java Mon Nov 10 16:47:56
2014
@@ -22,8 +22,6 @@ import javax.servlet.http.HttpUpgradeHan
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
-import org.apache.tomcat.jni.Socket;
-import org.apache.tomcat.util.net.AprEndpoint.AprSocketWrapper;
 import org.apache.tomcat.util.net.SocketWrapperBase;
 
 public class AprProcessor extends AbstractProcessor<Long> {
@@ -39,7 +37,7 @@ public class AprProcessor extends Abstra
         super(httpUpgradeHandler,
                 new UpgradeServletInputStream(wrapper),
                 new UpgradeServletOutputStream(wrapper, asyncWriteBufferSize));
-        ((AprSocketWrapper) wrapper).setLeftOverInput(leftOverInput);
-        Socket.timeoutSet(wrapper.getSocket().longValue(), INFINITE_TIMEOUT);
+        wrapper.unRead(leftOverInput);
+        wrapper.setTimeout(INFINITE_TIMEOUT);
     }
 }

Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2Processor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2Processor.java?rev=1637940&r1=1637939&r2=1637940&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2Processor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/Nio2Processor.java Mon Nov 10 16:47:56
2014
@@ -38,10 +38,7 @@ public class Nio2Processor extends Abstr
         super(httpUpgradeHandler,
                 new UpgradeServletInputStream(wrapper),
                 new UpgradeServletOutputStream(wrapper, asyncWriteBufferSize));
-
+        wrapper.unRead(leftoverInput);
         wrapper.setTimeout(INFINITE_TIMEOUT);
-        if (leftoverInput != null) {
-            wrapper.getSocket().getBufHandler().getReadBuffer().put(leftoverInput);
-        }
     }
 }

Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioProcessor.java?rev=1637940&r1=1637939&r2=1637940&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioProcessor.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/NioProcessor.java Mon Nov 10 16:47:56
2014
@@ -38,17 +38,7 @@ public class NioProcessor extends Abstra
         super(httpUpgradeHandler,
                 new UpgradeServletInputStream(wrapper),
                 new UpgradeServletOutputStream(wrapper, asyncWriteBufferSize));
-
+        wrapper.unRead(leftoverInput);
         wrapper.setTimeout(INFINITE_TIMEOUT);
-        if (leftoverInput != null) {
-            ByteBuffer readBuffer = wrapper.getSocket().getBufHandler().getReadBuffer();
-            if (readBuffer.remaining() > 0) {
-                readBuffer.flip();
-            } else {
-                readBuffer.clear();
-            }
-            readBuffer.put(leftoverInput);
-            readBuffer.flip();
-        }
     }
 }

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1637940&r1=1637939&r2=1637940&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Mon Nov 10 16:47:56 2014
@@ -2357,7 +2357,7 @@ public class AprEndpoint extends Abstrac
 
         private final ByteBuffer sslOutputBuffer;
 
-        private volatile ByteBuffer leftOverInput;
+        private volatile ByteBuffer returnedInput;
         private volatile boolean eagain = false;
         private volatile boolean closed = false;
 
@@ -2377,14 +2377,6 @@ public class AprEndpoint extends Abstrac
         }
 
 
-        public void setLeftOverInput(ByteBuffer leftOverInput) {
-            if (leftOverInput != null) {
-                this.leftOverInput = ByteBuffer.allocate(leftOverInput.remaining());
-                this.leftOverInput.put(leftOverInput);
-            }
-        }
-
-
         @Override
         public int read(boolean block, byte[] b, int off, int len) throws IOException {
 
@@ -2392,13 +2384,13 @@ public class AprEndpoint extends Abstrac
                 throw new IOException(sm.getString("socket.apr.closed", getSocket()));
             }
 
-            if (leftOverInput != null) {
-                if (leftOverInput.remaining() < len) {
-                    len = leftOverInput.remaining();
-                }
-                leftOverInput.get(b, off, len);
-                if (leftOverInput.remaining() == 0) {
-                    leftOverInput = null;
+            if (returnedInput != null) {
+                if (returnedInput.remaining() < len) {
+                    len = returnedInput.remaining();
+                }
+                returnedInput.get(b, off, len);
+                if (returnedInput.remaining() == 0) {
+                    returnedInput = null;
                 }
                 return len;
             }
@@ -2475,6 +2467,16 @@ public class AprEndpoint extends Abstrac
         }
 
 
+
+        @Override
+        public void unRead(ByteBuffer input) {
+            if (returnedInput != null) {
+                this.returnedInput = ByteBuffer.allocate(returnedInput.remaining());
+                this.returnedInput.put(returnedInput);
+            }
+        }
+
+
         @Override
         public void close() {
             closed = true;

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1637940&r1=1637939&r2=1637940&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Mon Nov 10 16:47:56 2014
@@ -942,6 +942,14 @@ public class Nio2Endpoint extends Abstra
 
 
         @Override
+        public void unRead(ByteBuffer returnedInput) {
+            if (returnedInput != null) {
+                getSocket().getBufHandler().getReadBuffer().put(returnedInput);
+            }
+        }
+
+
+        @Override
         public void close() throws IOException {
             getSocket().close();
         }

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1637940&r1=1637939&r2=1637940&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Mon Nov 10 16:47:56 2014
@@ -1479,6 +1479,21 @@ public class NioEndpoint extends Abstrac
 
 
         @Override
+        public void unRead(ByteBuffer returnedInput) {
+            if (returnedInput != null) {
+                ByteBuffer readBuffer = getSocket().getBufHandler().getReadBuffer();
+                if (readBuffer.remaining() > 0) {
+                    readBuffer.flip();
+                } else {
+                    readBuffer.clear();
+                }
+                readBuffer.put(returnedInput);
+                readBuffer.flip();
+            }
+        }
+
+
+        @Override
         public void close() throws IOException {
             getSocket().close();
         }

Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java?rev=1637940&r1=1637939&r2=1637940&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketWrapperBase.java Mon Nov 10 16:47:56
2014
@@ -17,6 +17,7 @@
 package org.apache.tomcat.util.net;
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.util.Iterator;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
@@ -188,6 +189,18 @@ public abstract class SocketWrapperBase<
 
     public abstract int read(boolean block, byte[] b, int off, int len) throws IOException;
     public abstract boolean isReady() throws IOException;
+    /**
+     * Return input that has been read to the input buffer for re-reading by the
+     * correct component. There are times when a component may read more data
+     * than it needs before it passes control to another component. One example
+     * of this is during HTTP upgrade. If an (arguably misbehaving client) sends
+     * data associated with the upgraded protocol before the HTTP upgrade
+     * completes, the HTTP handler may read it. This method provides a way for
+     * that data to be returned so it can be processed by the correct component.
+     *
+     * @param input The input to return to the input buffer.
+     */
+    public abstract void unRead(ByteBuffer input);
     public abstract void close() throws IOException;
 
     public abstract int write(boolean block, byte[] b, int off, int len) throws IOException;



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message