Author: markt
Date: Fri Jun 21 20:35:58 2013
New Revision: 1495588
URL: http://svn.apache.org/r1495588
Log:
WebSocket 1.0. Section 2.1.5.
The close message needs to be sent before Endpoint.onClose() is called.
Modified:
tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java?rev=1495588&r1=1495587&r2=1495588&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Fri Jun 21
20:35:58 2013
@@ -257,7 +257,7 @@ public class WsSession implements Sessio
@Override
public boolean isOpen() {
- return state == State.OPEN || state == State.PRE_CLOSING;
+ return state == State.OPEN;
}
@@ -342,15 +342,11 @@ public class WsSession implements Sessio
return;
}
- // This state exists to protect against recursive calls to close()
- // from Endpoint.onClose()
- state = State.PRE_CLOSING;
-
- fireEndpointOnClose(closeReason);
-
state = State.CLOSING;
sendCloseMessage(closeReason);
+
+ fireEndpointOnClose(closeReason);
}
}
@@ -371,18 +367,15 @@ public class WsSession implements Sessio
return;
}
- // This state exists to protect against recursive calls to close()
- // from Endpoint.onClose()
- state = State.PRE_CLOSING;
+ state = State.CLOSING;
+
+ sendCloseMessage(closeReason);
CloseReason localCloseReason =
new CloseReason(CloseCodes.CLOSED_ABNORMALLY,
closeReason.getReasonPhrase());
- fireEndpointOnClose(localCloseReason);
- state = State.CLOSING;
-
- sendCloseMessage(closeReason);
+ fireEndpointOnClose(localCloseReason);
}
}
@@ -394,20 +387,14 @@ public class WsSession implements Sessio
*/
public void onClose(CloseReason closeReason) {
- boolean sendCloseMessage = false;
-
synchronized (stateLock) {
if (state == State.OPEN) {
- sendCloseMessage = true;
+ sendCloseMessage(closeReason);
fireEndpointOnClose(closeReason);
}
state = State.CLOSED;
- if (sendCloseMessage) {
- sendCloseMessage(closeReason);
- }
-
// Close the socket
wsRemoteEndpoint.close();
}
@@ -547,7 +534,6 @@ public class WsSession implements Sessio
private static enum State {
OPEN,
- PRE_CLOSING,
CLOSING,
CLOSED
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]