Skip to content

Commit

Permalink
[wpinet] WebSocket: Improve disconnect reason reporting (#6262)
Browse files Browse the repository at this point in the history
Add "remote close:" to messages coming from the remote end.
Previously it was impossible to tell if the error was on the local side
or communicated by the remote side.
  • Loading branch information
PeterJohnson committed Jan 20, 2024
1 parent 0e5eb3f commit 24a24c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions wpinet/src/main/native/cpp/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ void WebSocket::HandleIncoming(uv::Buffer& buf, size_t size) {
if (m_state != CLOSING) {
SendClose(code, reason);
}
SetClosed(code, reason);
SetClosed(code, fmt::format("remote close: {}", reason));
// If we're the server, shutdown the connection.
if (m_server) {
Shutdown();
Expand Down Expand Up @@ -675,7 +675,8 @@ void WebSocket::HandleIncoming(uv::Buffer& buf, size_t size) {
pong(m_controlPayload);
break;
default:
return Fail(1002, "invalid message opcode");
return Fail(1002, fmt::format("invalid message opcode {}",
static_cast<unsigned int>(opcode)));
}

// Prepare for next message
Expand Down
4 changes: 2 additions & 2 deletions wpinet/src/test/native/cpp/WebSocketServerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ TEST_F(WebSocketServerTest, CloseReason) {
ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1000);
ASSERT_EQ(reason, "hangup");
ASSERT_EQ(reason, "remote close: hangup");
});
};
// need to respond with close for server to finish shutdown
Expand Down Expand Up @@ -237,7 +237,7 @@ TEST_F(WebSocketServerTest, ReceiveCloseReason) {
ws->closed.connect([&](uint16_t code, std::string_view reason) {
++gotClosed;
ASSERT_EQ(code, 1000);
ASSERT_EQ(reason, "hangup");
ASSERT_EQ(reason, "remote close: hangup");
});
};
const uint8_t contents[] = {0x03u, 0xe8u, 'h', 'a', 'n', 'g', 'u', 'p'};
Expand Down

0 comments on commit 24a24c9

Please sign in to comment.