Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1418: WebSocketServer sometimes misses GET request after SSL handshake #1419

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/java/org/java_websocket/SSLSocketChannel2.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public SSLSocketChannel2(SocketChannel channel, SSLEngine sslEngine, ExecutorSer
createBuffers(sslEngine.getSession());
// kick off handshake
socketChannel.write(wrap(emptybuffer));// initializes res
processHandshake();
processHandshake(false);
}

private void consumeFutureUninterruptible(Future<?> f) {
Expand All @@ -148,7 +148,7 @@ private void consumeFutureUninterruptible(Future<?> f) {
* This method will do whatever necessary to process the sslEngine handshake. Thats why it's
* called both from the {@link #read(ByteBuffer)} and {@link #write(ByteBuffer)}
**/
private synchronized void processHandshake() throws IOException {
private synchronized void processHandshake(boolean isReading) throws IOException {
if (sslEngine.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING) {
return; // since this may be called either from a reading or a writing thread and because this method is synchronized it is necessary to double check if we are still handshaking.
}
Expand All @@ -167,7 +167,7 @@ private synchronized void processHandshake() throws IOException {
}
}

if (sslEngine.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_UNWRAP) {
if (isReading && sslEngine.getHandshakeStatus() == SSLEngineResult.HandshakeStatus.NEED_UNWRAP) {
if (!isBlocking() || readEngineResult.getStatus() == Status.BUFFER_UNDERFLOW) {
inCrypt.compact();
int read = socketChannel.read(inCrypt);
Expand Down Expand Up @@ -273,7 +273,7 @@ protected void createBuffers(SSLSession session) {

public int write(ByteBuffer src) throws IOException {
if (!isHandShakeComplete()) {
processHandshake();
processHandshake(false);
return 0;
}
// assert(bufferallocations > 1); // see #190
Expand Down Expand Up @@ -303,10 +303,10 @@ public int read(ByteBuffer dst) throws IOException {
if (!isHandShakeComplete()) {
if (isBlocking()) {
while (!isHandShakeComplete()) {
processHandshake();
processHandshake(true);
}
} else {
processHandshake();
processHandshake(true);
if (!isHandShakeComplete()) {
return 0;
}
Expand Down
Loading