Skip to content

Commit

Permalink
PR spring-projects#32097 - changes to address reviews for websocket
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <[email protected]>
  • Loading branch information
lachlan-roberts committed Jun 22, 2024
1 parent d415757 commit 0b4b65f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.jetty.io.ArrayByteBufferPool;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.websocket.server.WebSocketUpgradeHandler;
import org.eclipse.jetty.websocket.server.ServerWebSocketContainer;

import org.springframework.http.server.reactive.JettyCoreHttpHandlerAdapter;

Expand Down Expand Up @@ -51,9 +51,7 @@ protected void initServer() {
this.jettyServer.addConnector(connector);
this.jettyServer.setHandler(createHandlerAdapter());

// TODO: We don't actually want the upgrade handler but this will create the WebSocketContainer.
// This requires a change in Jetty.
WebSocketUpgradeHandler.from(jettyServer);
ServerWebSocketContainer.ensure(jettyServer);
}

private JettyCoreHttpHandlerAdapter createHandlerAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@ public JettyWebSocketSession(Session session, HandshakeInfo info, DataBufferFact
this.lock.lock();
try {
this.requested = Math.addExact(this.requested, n);
if (this.requested < 0L) {
this.requested = Long.MAX_VALUE;
}

if (!this.awaitingMessage && this.requested > 0) {
this.requested--;
if (this.requested != Long.MAX_VALUE) {
this.requested--;
}
this.awaitingMessage = true;
demand = true;
}
Expand Down Expand Up @@ -113,7 +119,9 @@ void handleMessage(WebSocketMessage message) {
}
this.awaitingMessage = false;
if (this.requested > 0) {
this.requested--;
if (this.requested != Long.MAX_VALUE) {
this.requested--;
}
this.awaitingMessage = true;
demand = true;
}
Expand Down

0 comments on commit 0b4b65f

Please sign in to comment.