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
public enum READYSTATE {
18-
NOTYETCONNECTED, CONNECTING, OPEN, CLOSING, CLOSED;
18+
NOT_YET_CONNECTED, CONNECTING, OPEN, CLOSING, CLOSED;
1919
}
2020

2121
public static int RCVBUF = 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
private volatile boolean flushandclosestate = false;
7777

78-
private READYSTATE readystate = READYSTATE.NOTYETCONNECTED;
78+
private READYSTATE readystate = READYSTATE.NOT_YET_CONNECTED;
7979

8080
/**
8181
* The listener to notify of WebSocket events.
@@ -203,7 +203,7 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
203203
return false;
204204
} catch ( RuntimeException e ) {
205205
wsl.onWebsocketError( this, e );
206-
flushAndClose( CloseFrame.NEVERCONNECTED, e.getMessage(), false );
206+
flushAndClose( CloseFrame.NEVER_CONNECTED, e.getMessage(), false );
207207
return false;
208208
}
209209
write( d.createHandshake( d.postProcessHandshakeResponseAsServer( handshake, response ), role ) );
@@ -254,7 +254,7 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
254254
return false;
255255
} catch ( RuntimeException e ) {
256256
wsl.onWebsocketError( this, e );
257-
flushAndClose( CloseFrame.NEVERCONNECTED, e.getMessage(), false );
257+
flushAndClose( CloseFrame.NEVER_CONNECTED, e.getMessage(), false );
258258
return false;
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
public void eot() {
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
} else if( 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
public READYSTATE getReadyState() {
345345
if( conn == null ) {
346-
return READYSTATE.NOTYETCONNECTED;
346+
return READYSTATE.NOT_YET_CONNECTED;
347347
}
348348
return conn.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
public static final int TLS_ERROR = 1015;
9090

9191
/** The connection had never been established */
92-
public static final int NEVERCONNECTED = -1;
92+
public static final int NEVER_CONNECTED = -1;
9393
public static final int BUGGYCLOSE = -2;
9494
public static final int FLASHPOLICY = -3;
9595

0 commit comments

Comments
 (0)