mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[wpinet] WebSocket: When Close() is called, call closed immediately (#5047)
This provides the closed callback with the real reason for the connection being closed. Keep closed from being called twice by adding a check in SetClosed().
This commit is contained in:
@@ -126,6 +126,7 @@ void WebSocket::Close(uint16_t code, std::string_view reason) {
|
||||
SendClose(code, reason);
|
||||
if (m_state != FAILED && m_state != CLOSED) {
|
||||
m_state = CLOSING;
|
||||
closed(code, reason);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,8 +338,11 @@ void WebSocket::SetClosed(uint16_t code, std::string_view reason, bool failed) {
|
||||
if (m_state == FAILED || m_state == CLOSED) {
|
||||
return;
|
||||
}
|
||||
bool wasClosing = m_state == CLOSING;
|
||||
m_state = failed ? FAILED : CLOSED;
|
||||
closed(code, reason);
|
||||
if (!wasClosing) {
|
||||
closed(code, reason);
|
||||
}
|
||||
}
|
||||
|
||||
void WebSocket::Shutdown() {
|
||||
|
||||
@@ -125,13 +125,13 @@ TEST_F(WebSocketIntegrationTest, ClientSendText) {
|
||||
++gotData;
|
||||
ASSERT_EQ(data, "hello");
|
||||
});
|
||||
ws.closed.connect([&](auto code, auto reason) { Finish(); });
|
||||
});
|
||||
});
|
||||
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
Finish();
|
||||
if (code != 1005 && code != 1006) {
|
||||
FAIL() << "Code: " << code << " Reason: " << reason;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user