Author: markt Date: Fri Jun 21 14:05:40 2013 New Revision: 1495445 URL: http://svn.apache.org/r1495445 Log: WebSocket 1.0. Section 2.1.5. Session expiry must be signalled to the local endpoint with a close code of 1006.
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Modified: tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties?rev=1495445&r1=1495444&r2=1495445&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/LocalStrings.properties Fri Jun 21 14:05:40 2013 @@ -57,7 +57,6 @@ wsSession.closed=The WebSocket session h wsSession.duplicateHandlerBinary=A binary message handler has already been configured wsSession.duplicateHandlerPong=A pong message handler has already been configured wsSession.duplicateHandlerText=A text message handler has already been configured -wsSession.expireFailed=Unable to close expired session cleanly wsSession.sendCloseFail=Failed to send close message to remote endpoint wsSession.invalidHandlerTypePong=A pong message handler must implement MessageHandler.Basic wsSession.removeHandlerFailed=Unable to remove the handler [{0}] as it was not registered with this session 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=1495445&r1=1495444&r2=1495445&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/WsSession.java Fri Jun 21 14:05:40 2013 @@ -356,6 +356,38 @@ public class WsSession implements Sessio /** + * WebSocket 1.0. Section 2.1.5. + * Need internal close method as spec requires that the local endpoint + * receives a 1006 on timeout. + */ + private void closeTimeout(CloseReason closeReason) { + // Double-checked locking. OK because state is volatile + if (state != State.OPEN) { + return; + } + + synchronized (stateLock) { + if (state != State.OPEN) { + return; + } + + // This state exists to protect against recursive calls to close() + // from Endpoint.onClose() + state = State.PRE_CLOSING; + + CloseReason localCloseReason = + new CloseReason(CloseCodes.CLOSED_ABNORMALLY, + closeReason.getReasonPhrase()); + fireEndpointOnClose(localCloseReason); + + state = State.CLOSING; + + sendCloseMessage(closeReason); + } + } + + + /** * Called when a close message is received. Should only ever happen once. * Also called after a protocol error when the ProtocolHandler needs to * force the closing of the connection. @@ -501,12 +533,8 @@ public class WsSession implements Sessio } if (System.currentTimeMillis() - lastActive > timeout) { - try { - close(new CloseReason(CloseCodes.GOING_AWAY, - sm.getString("wsSession.timeout"))); - } catch (IOException e) { - log.warn(sm.getString("wsSession.expireFailed"), e); - } + closeTimeout(new CloseReason(CloseCodes.GOING_AWAY, + sm.getString("wsSession.timeout"))); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org