[ntcore] Improve disconnect error reporting (#5085)

Also fix memory leak in WebSocketConnection destructor.
This commit is contained in:
Peter Johnson
2023-02-11 22:56:29 -08:00
committed by GitHub
parent 01f0394419
commit e57ded8c39
5 changed files with 21 additions and 5 deletions

View File

@@ -2289,9 +2289,10 @@ void ServerImpl::SendControl(uint64_t curTimeMs) {
}
void ServerImpl::SendValues(int clientId, uint64_t curTimeMs) {
auto client = m_impl->m_clients[clientId].get();
client->SendOutgoing(curTimeMs);
client->Flush();
if (auto client = m_impl->m_clients[clientId].get()) {
client->SendOutgoing(curTimeMs);
client->Flush();
}
}
void ServerImpl::HandleLocal(std::span<const ClientMessage> msgs) {

View File

@@ -25,6 +25,12 @@ WebSocketConnection::~WebSocketConnection() {
for (auto&& buf : m_buf_pool) {
buf.Deallocate();
}
for (auto&& buf : m_text_buffers) {
buf.Deallocate();
}
for (auto&& buf : m_binary_buffers) {
buf.Deallocate();
}
}
void WebSocketConnection::Flush() {
@@ -64,6 +70,7 @@ void WebSocketConnection::Flush() {
}
void WebSocketConnection::Disconnect(std::string_view reason) {
m_reason = reason;
m_ws.Close(1005, reason);
}

View File

@@ -5,6 +5,8 @@
#pragma once
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <wpi/SmallVector.h>
@@ -34,6 +36,8 @@ class WebSocketConnection final
void Disconnect(std::string_view reason) final;
std::string_view GetDisconnectReason() const { return m_reason; }
private:
void StartSendText() final;
void FinishSendText() final;
@@ -64,6 +68,7 @@ class WebSocketConnection final
size_t m_binary_pos = 0;
bool m_in_text = false;
int m_sendsActive = 0;
std::string m_reason;
};
} // namespace nt::net