Lifecycle management for sockets.
This commit is contained in:
@@ -552,7 +552,6 @@ public:
|
|||||||
{
|
{
|
||||||
FinalCleanup();
|
FinalCleanup();
|
||||||
}
|
}
|
||||||
Lv2Log::error("PiPedalSocketHandler deleted");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-2
@@ -754,7 +754,11 @@ namespace pipedal
|
|||||||
public:
|
public:
|
||||||
~WebSocketSession()
|
~WebSocketSession()
|
||||||
{
|
{
|
||||||
this->socketHandler = nullptr;
|
if (this->socketHandler)
|
||||||
|
{
|
||||||
|
this->socketHandler->onSocketClosed();
|
||||||
|
this->socketHandler = nullptr;
|
||||||
|
}
|
||||||
webSocket = nullptr;
|
webSocket = nullptr;
|
||||||
pServer = nullptr;
|
pServer = nullptr;
|
||||||
Lv2Log::info(SS("WebSocketSession closed. " << fromAddress));
|
Lv2Log::info(SS("WebSocketSession closed. " << fromAddress));
|
||||||
@@ -819,7 +823,10 @@ namespace pipedal
|
|||||||
std::lock_guard<std::recursive_mutex> lock{m_sessionsMutex};
|
std::lock_guard<std::recursive_mutex> lock{m_sessionsMutex};
|
||||||
m_sessions.erase(session);
|
m_sessions.erase(session);
|
||||||
m_connections.erase(hConnection);
|
m_connections.erase(hConnection);
|
||||||
session = nullptr; // probably delete here.
|
if (session != nullptr)
|
||||||
|
{
|
||||||
|
session = nullptr; // probably delete here.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotFound(server::connection_type &connection, const std::string &filename)
|
void NotFound(server::connection_type &connection, const std::string &filename)
|
||||||
|
|||||||
+11
-3
@@ -81,7 +81,6 @@ class WebServerImpl;
|
|||||||
class SocketHandler {
|
class SocketHandler {
|
||||||
friend class WebServerImpl;
|
friend class WebServerImpl;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
class IWriteCallback {
|
class IWriteCallback {
|
||||||
public:
|
public:
|
||||||
virtual void close() = 0;
|
virtual void close() = 0;
|
||||||
@@ -100,6 +99,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual void onSocketClosed() = 0;
|
||||||
virtual void onReceive(const std::string_view&text) = 0;
|
virtual void onReceive(const std::string_view&text) = 0;
|
||||||
public:
|
public:
|
||||||
std::string getFromAddress() const { return writeCallback_->getFromAddress(); }
|
std::string getFromAddress() const { return writeCallback_->getFromAddress(); }
|
||||||
@@ -112,12 +112,20 @@ public:
|
|||||||
writeCallback_->writeCallback(text);
|
writeCallback_->writeCallback(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
virtual void OnSocketClosed()
|
||||||
|
{
|
||||||
|
writeCallback_ = nullptr;
|
||||||
|
}
|
||||||
virtual void Close()
|
virtual void Close()
|
||||||
{
|
{
|
||||||
writeCallback_->close();
|
if (writeCallback_ != nullptr)
|
||||||
|
{
|
||||||
|
writeCallback_->close();
|
||||||
|
writeCallback_ = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~SocketHandler() = default;
|
virtual ~SocketHandler() {}
|
||||||
|
|
||||||
virtual void onAttach() { }
|
virtual void onAttach() { }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user