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
package org.java_websocket;
77

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

23-
import javax.net.ssl.SSLEngine;
24-
import javax.net.ssl.SSLEngineResult;
25-
import javax.net.ssl.SSLEngineResult.HandshakeStatus;
26-
import javax.net.ssl.SSLEngineResult.Status;
27-
import javax.net.ssl.SSLException;
28-
import javax.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
int num = socketChannel.write( wrap( src ) );
216+
if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) {
217+
throw new EOFException("Connection is closed");
218+
}
216219
return num;
217220

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

0 commit comments

Comments
 (0)