Skip to content

Commit be65bdb

Browse files
committed
made the close code for connections that never completed the initial handshake CloseFrame.NEVER_CONNECTED instead of CloseFrame.ABNORMAL_CLOSE and renamed NOTYETCONNECTED to NOT_YET_CONNECTED and CloseFrame.NEVERCONNECTED to CloseFrame.NEVER_CONNECTED
1 parent 8009a69 commit be65bdb

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

‎src/main/java/org/java_websocket/WebSocket.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public enum Role{
1515
}
1616

1717
publicenumREADYSTATE{
18-
NOTYETCONNECTED, CONNECTING, OPEN, CLOSING, CLOSED;
18+
NOT_YET_CONNECTED, CONNECTING, OPEN, CLOSING, CLOSED;
1919
}
2020

2121
publicstaticintRCVBUF = 16384;

‎src/main/java/org/java_websocket/WebSocketImpl.java‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class WebSocketImpl extends WebSocket{
7575
/** When true no further frames may be submitted to be sent */
7676
privatevolatilebooleanflushandclosestate = false;
7777

78-
privateREADYSTATEreadystate = READYSTATE.NOTYETCONNECTED;
78+
privateREADYSTATEreadystate = READYSTATE.NOT_YET_CONNECTED;
7979

8080
/**
8181
* The listener to notify of WebSocket events.
@@ -203,7 +203,7 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ){
203203
returnfalse;
204204
} catch ( RuntimeExceptione ){
205205
wsl.onWebsocketError( this, e );
206-
flushAndClose( CloseFrame.NEVERCONNECTED, e.getMessage(), false );
206+
flushAndClose( CloseFrame.NEVER_CONNECTED, e.getMessage(), false );
207207
returnfalse;
208208
}
209209
write( d.createHandshake( d.postProcessHandshakeResponseAsServer( handshake, response ), role ) );
@@ -254,7 +254,7 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ){
254254
returnfalse;
255255
} catch ( RuntimeExceptione ){
256256
wsl.onWebsocketError( this, e );
257-
flushAndClose( CloseFrame.NEVERCONNECTED, e.getMessage(), false );
257+
flushAndClose( CloseFrame.NEVER_CONNECTED, e.getMessage(), false );
258258
returnfalse;
259259
}
260260
open( handshake );
@@ -399,7 +399,7 @@ private void close( int code, String message, boolean remote ){
399399
assert ( remote );
400400
flushAndClose( CloseFrame.FLASHPOLICY, message, true );
401401
} else{
402-
flushAndClose( CloseFrame.NEVERCONNECTED, message, false );
402+
flushAndClose( CloseFrame.NEVER_CONNECTED, message, false );
403403
}
404404
if( code == CloseFrame.PROTOCOL_ERROR )// this endpoint found a PROTOCOL_ERROR
405405
flushAndClose( code, message, remote );
@@ -487,6 +487,9 @@ protected synchronized void flushAndClose( int code, String message, boolean rem
487487
}
488488

489489
publicvoideot(){
490+
if( getReadyState() == READYSTATE.NOT_YET_CONNECTED ){
491+
closeConnection( CloseFrame.NEVER_CONNECTED, true );
492+
}
490493
if( draft == null ){
491494
closeConnection( CloseFrame.ABNORMAL_CLOSE, true );
492495
} elseif( draft.getCloseHandshakeType() == CloseHandshakeType.NONE ){

‎src/main/java/org/java_websocket/client/WebSocketClient.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ private final void interruptableRun(){
234234
selector.select( timeout );
235235
Set<SelectionKey> keys = selector.selectedKeys();
236236
Iterator<SelectionKey> i = keys.iterator();
237-
if( conn.getReadyState() == READYSTATE.NOTYETCONNECTED && !i.hasNext() ){
237+
if( conn.getReadyState() == READYSTATE.NOT_YET_CONNECTED && !i.hasNext() ){
238238
// Hack for issue #140:
239239
// Android does simply return form select without closing the channel if address is not reachable(which seems to be a bug in the android nio proivder)
240240
// TODO provide a way to fix this problem which does not require this hack
@@ -343,7 +343,7 @@ private void sendHandshake() throws InvalidHandshakeException{
343343
*/
344344
publicREADYSTATEgetReadyState(){
345345
if( conn == null ){
346-
returnREADYSTATE.NOTYETCONNECTED;
346+
returnREADYSTATE.NOT_YET_CONNECTED;
347347
}
348348
returnconn.getReadyState();
349349
}

‎src/main/java/org/java_websocket/framing/CloseFrame.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public interface CloseFrame extends Framedata{
8989
publicstaticfinalintTLS_ERROR = 1015;
9090

9191
/** The connection had never been established */
92-
publicstaticfinalintNEVERCONNECTED = -1;
92+
publicstaticfinalintNEVER_CONNECTED = -1;
9393
publicstaticfinalintBUGGYCLOSE = -2;
9494
publicstaticfinalintFLASHPOLICY = -3;
9595

0 commit comments

Comments
(0)