diff --git a/wpiutil/src/main/native/cpp/HttpServerConnection.cpp b/wpiutil/src/main/native/cpp/HttpServerConnection.cpp index b395b6c16f..9e65691470 100644 --- a/wpiutil/src/main/native/cpp/HttpServerConnection.cpp +++ b/wpiutil/src/main/native/cpp/HttpServerConnection.cpp @@ -31,7 +31,7 @@ HttpServerConnection::HttpServerConnection(std::shared_ptr stream) }); // pass incoming data to HTTP parser - m_headerConn = + m_dataConn = stream->data.connect_connection([this](uv::Buffer& buf, size_t size) { m_request.Execute(StringRef{buf.base, size}); if (m_request.HasError()) { @@ -41,7 +41,8 @@ HttpServerConnection::HttpServerConnection(std::shared_ptr stream) }); // close when remote side closes - stream->end.connect([h = stream.get()] { h->Close(); }); + m_endConn = + stream->end.connect_connection([h = stream.get()] { h->Close(); }); // start reading stream->StartRead(); diff --git a/wpiutil/src/main/native/cpp/WebSocketServer.cpp b/wpiutil/src/main/native/cpp/WebSocketServer.cpp index 2bd8e38d48..3ad5e0e34e 100644 --- a/wpiutil/src/main/native/cpp/WebSocketServer.cpp +++ b/wpiutil/src/main/native/cpp/WebSocketServer.cpp @@ -86,7 +86,7 @@ WebSocketServer::WebSocketServer(uv::Stream& stream, StringRef protocol = m_helper.MatchProtocol(protocols).second; // Disconnect our header reader - m_headerConn.disconnect(); + m_dataConn.disconnect(); // Accepting the stream may destroy this (as it replaces the stream user // data), so grab a shared pointer first. @@ -104,14 +104,15 @@ WebSocketServer::WebSocketServer(uv::Stream& stream, // Set up stream stream.StartRead(); - m_headerConn = + m_dataConn = stream.data.connect_connection([this](uv::Buffer& buf, size_t size) { if (m_aborted) return; m_req.Execute(StringRef{buf.base, size}); if (m_req.HasError()) Abort(400, "Bad Request"); }); - stream.error.connect([this](uv::Error) { m_stream.Close(); }); - stream.end.connect([this] { m_stream.Close(); }); + m_errorConn = + stream.error.connect_connection([this](uv::Error) { m_stream.Close(); }); + m_endConn = stream.end.connect_connection([this] { m_stream.Close(); }); } std::shared_ptr WebSocketServer::Create( diff --git a/wpiutil/src/main/native/include/wpi/HttpServerConnection.h b/wpiutil/src/main/native/include/wpi/HttpServerConnection.h index 234c601cf3..c49c2a29bb 100644 --- a/wpiutil/src/main/native/include/wpi/HttpServerConnection.h +++ b/wpiutil/src/main/native/include/wpi/HttpServerConnection.h @@ -139,7 +139,10 @@ class HttpServerConnection { uv::Stream& m_stream; /** The header reader connection. */ - sig::Connection m_headerConn; + sig::ScopedConnection m_dataConn; + + /** The end stream connection. */ + sig::ScopedConnection m_endConn; /** The message complete connection. */ sig::Connection m_messageCompleteConn; diff --git a/wpiutil/src/main/native/include/wpi/WebSocketServer.h b/wpiutil/src/main/native/include/wpi/WebSocketServer.h index bad3f68d8f..c324c99b9a 100644 --- a/wpiutil/src/main/native/include/wpi/WebSocketServer.h +++ b/wpiutil/src/main/native/include/wpi/WebSocketServer.h @@ -137,7 +137,9 @@ class WebSocketServer : public std::enable_shared_from_this { SmallVector m_protocols; ServerOptions m_options; bool m_aborted = false; - sig::Connection m_headerConn; + sig::ScopedConnection m_dataConn; + sig::ScopedConnection m_errorConn; + sig::ScopedConnection m_endConn; void Abort(uint16_t code, StringRef reason); };