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/02/22 19:49:32 UTC
svn commit: r1661516 -
/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
Author: markt
Date: Sun Feb 22 18:49:32 2015
New Revision: 1661516
URL: http://svn.apache.org/r1661516
Log:
Align ServletInputStream with required behaviour as clarified by recent
EG discussions.
Modified:
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
Modified: tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java?rev=1661516&r1=1661515&r2=1661516&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletInputStream.java Sun Feb 22 18:49:32 2015
@@ -38,6 +38,7 @@ public class UpgradeServletInputStream e
private final SocketWrapperBase<?> socketWrapper;
private volatile boolean closed = false;
+ private volatile boolean eof = false;
// Start in blocking-mode
private volatile Boolean ready = Boolean.TRUE;
private volatile ReadListener listener = null;
@@ -55,9 +56,7 @@ public class UpgradeServletInputStream e
throw new IllegalStateException(
sm.getString("upgrade.sis.isFinished.ise"));
}
- // The only way to finish an HTTP Upgrade connection is to close the
- // socket.
- return false;
+ return eof;
}
@@ -68,7 +67,7 @@ public class UpgradeServletInputStream e
sm.getString("upgrade.sis.isReady.ise"));
}
- if (closed) {
+ if (eof || closed) {
return false;
}
@@ -147,7 +146,11 @@ public class UpgradeServletInputStream e
preReadChecks();
try {
- return socketWrapper.read(listener == null, b, off, len);
+ int result = socketWrapper.read(listener == null, b, off, len);
+ if (result == -1) {
+ eof = true;
+ }
+ return result;
} catch (IOException ioe) {
close();
throw ioe;
@@ -158,6 +161,7 @@ public class UpgradeServletInputStream e
@Override
public void close() throws IOException {
+ eof = true;
closed = true;
}
@@ -188,9 +192,7 @@ public class UpgradeServletInputStream e
if (result == 0) {
return -1;
} else if (result == -1) {
- // Will never happen with a network socket. An IOException will be
- // thrown when the client closes the connection.
- // Echo back the -1 to be safe.
+ eof = true;
return -1;
} else {
return b[0] & 0xFF;
@@ -207,7 +209,12 @@ public class UpgradeServletInputStream e
ClassLoader originalClassLoader = thread.getContextClassLoader();
try {
thread.setContextClassLoader(applicationLoader);
- listener.onDataAvailable();
+ if (!eof) {
+ listener.onDataAvailable();
+ }
+ if (eof) {
+ listener.onAllDataRead();
+ }
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
onError(t);
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org