Author: markt
Date: Mon Jan 12 22:35:19 2015
New Revision: 1651219
URL: http://svn.apache.org/r1651219
Log:
Fix some flushing issues identified when running the Autobhan WebSocket test
suite
Modified:
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
Modified:
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java?rev=1651219&r1=1651218&r2=1651219&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
(original)
+++
tomcat/trunk/java/org/apache/coyote/http11/upgrade/UpgradeServletOutputStream.java
Mon Jan 12 22:35:19 2015
@@ -45,6 +45,8 @@ public class UpgradeServletOutputStream
// synchronization may be required (see fireListenerLock for an example).
private final Object writeLock = new Object();
+ private volatile boolean flushing = false;
+
private volatile boolean closeRequired = false;
// Start in blocking-mode
@@ -69,11 +71,17 @@ public class UpgradeServletOutputStream
}
// Make sure isReady() and onWritePossible() have a consistent view of
- // buffer and fireListener when determining if the listener should fire
+ // fireListener when determining if the listener should fire
synchronized (fireListenerLock) {
- boolean result = socketWrapper.isReadyForWrite();
- fireListener = !result;
- return result;
+ if (flushing) {
+ socketWrapper.registerWriteInterest();
+ fireListener = true;
+ return false;
+ } else {
+ boolean result = socketWrapper.isReadyForWrite();
+ fireListener = !result;
+ return result;
+ }
}
}
@@ -124,10 +132,30 @@ public class UpgradeServletOutputStream
@Override
public void flush() throws IOException {
- socketWrapper.flush(listener == null);
+ flushInternal(listener == null, true);
}
+ private void flushInternal(boolean block, boolean updateFlushing) throws
IOException {
+ try {
+ synchronized (writeLock) {
+ if (updateFlushing) {
+ flushing = socketWrapper.flush(block);
+ } else {
+ socketWrapper.flush(block);
+ }
+ }
+ } catch (Throwable t) {
+ ExceptionUtils.handleThrowable(t);
+ onError(t);
+ if (t instanceof IOException) {
+ throw (IOException) t;
+ } else {
+ throw new IOException(t);
+ }
+ }
+ }
+
@Override
public void close() throws IOException {
closeRequired = true;
@@ -156,18 +184,14 @@ public class UpgradeServletOutputStream
protected final void onWritePossible() throws IOException {
- try {
- synchronized (writeLock) {
- socketWrapper.flush(false);
- }
- } catch (Throwable t) {
- ExceptionUtils.handleThrowable(t);
- onError(t);
- if (t instanceof IOException) {
- throw t;
- } else {
- throw new IOException(t);
+ if (flushing) {
+ flushInternal(false, true);
+ if (flushing) {
+ socketWrapper.registerWriteInterest();
+ return;
}
+ } else {
+ flushInternal(false, false);
}
// Make sure isReady() and onWritePossible() have a consistent view
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java?rev=1651219&r1=1651218&r2=1651219&view=diff
==============================================================================
---
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
(original)
+++
tomcat/trunk/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
Mon Jan 12 22:35:19 2015
@@ -104,15 +104,17 @@ public class WsRemoteEndpointImplServer
}
if (complete) {
sos.flush();
- wsWriteTimeout.unregister(this);
- clearHandler(null, useDispatch);
- if (close) {
- close();
+ complete = sos.isReady();
+ if (complete) {
+ wsWriteTimeout.unregister(this);
+ clearHandler(null, useDispatch);
+ if (close) {
+ close();
+ }
}
break;
}
}
-
} catch (IOException ioe) {
wsWriteTimeout.unregister(this);
clearHandler(ioe, useDispatch);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]