Skip to content

Commit ea7e061

Browse files
fix 100% CPU issue
1 parent 05d2e2e commit ea7e061

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
*/
66
packageorg.java_websocket;
77

8+
importjavax.net.ssl.SSLEngine;
9+
importjavax.net.ssl.SSLEngineResult;
10+
importjavax.net.ssl.SSLEngineResult.HandshakeStatus;
11+
importjavax.net.ssl.SSLEngineResult.Status;
12+
importjavax.net.ssl.SSLException;
13+
importjavax.net.ssl.SSLSession;
14+
importjava.io.EOFException;
815
importjava.io.IOException;
916
importjava.net.Socket;
1017
importjava.net.SocketAddress;
@@ -20,13 +27,6 @@
2027
importjava.util.concurrent.ExecutorService;
2128
importjava.util.concurrent.Future;
2229

23-
importjavax.net.ssl.SSLEngine;
24-
importjavax.net.ssl.SSLEngineResult;
25-
importjavax.net.ssl.SSLEngineResult.HandshakeStatus;
26-
importjavax.net.ssl.SSLEngineResult.Status;
27-
importjavax.net.ssl.SSLException;
28-
importjavax.net.ssl.SSLSession;
29-
3030
/**
3131
* Implements the relevant portions of the SocketChannel interface with the SSLEngine wrapper.
3232
*/
@@ -213,6 +213,9 @@ public int write( ByteBuffer src ) throws IOException{
213213
// createBuffers( sslEngine.getSession() );
214214
//}
215215
intnum = socketChannel.write( wrap( src ) );
216+
if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED){
217+
thrownewEOFException("Connection is closed");
218+
}
216219
returnnum;
217220

218221
}
@@ -286,6 +289,9 @@ private int readRemaining( ByteBuffer dst ) throws SSLException{
286289
if( inCrypt.hasRemaining() ){
287290
unwrap();
288291
intamount = transfereTo( inData, dst );
292+
if (readEngineResult.getStatus() == SSLEngineResult.Status.CLOSED){
293+
return -1;
294+
}
289295
if( amount > 0 )
290296
returnamount;
291297
}

0 commit comments

Comments
(0)