Websocket: allow a hard shutdown after flushing data.

Don't wait for the other end to acknowledge closing the socket.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: If5e4bb6d9c5148c0e0c61d59c233f6cf5594c577
pull/8667/head
Michael Meeks 2024-03-29 10:47:43 +00:00 committed by Caolán McNamara
parent df343fc5fa
commit 9e0cef08c2
1 changed files with 13 additions and 1 deletions

View File

@ -238,7 +238,8 @@ protected:
public:
void shutdown(const StatusCodes statusCode = StatusCodes::NORMAL_CLOSE,
const std::string& statusMessage = std::string())
const std::string& statusMessage = std::string(),
bool hardShutdown = false)
{
std::shared_ptr<StreamSocket> socket = _socket.lock();
if (socket)
@ -250,6 +251,10 @@ public:
socket->ignoreInput();
assert(socket->getInBuffer().empty() &&
"Socket buffer must be empty after ignoreInput");
// force close after writing this message
if (hardShutdown)
socket->shutdown();
}
_wsPayload.clear();
@ -259,6 +264,13 @@ public:
_shuttingDown = false;
}
/// Don't wait for the remote Websocket to handshake with us; go down fast.
void shutdownAfterWriting()
{
shutdown(WebSocketHandler::StatusCodes::NORMAL_CLOSE, std::string(),
true /* hard async shutdown & close */);
}
private:
bool handleTCPStream(const std::shared_ptr<StreamSocket>& socket)
{