Hold shared pointer from the very beginning (#1537)

This commit is contained in:
Martin Chang 2023-03-18 18:38:55 +08:00 committed by GitHub
parent 2af8e47278
commit c63b021e7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -372,6 +372,7 @@ void WebSocketConnectionImpl::onNewMessage(
const trantor::TcpConnectionPtr &connPtr,
trantor::MsgBuffer *buffer)
{
auto self = shared_from_this();
while (buffer->readableBytes() > 0)
{
auto success = parser_.parse(buffer);
@ -397,7 +398,7 @@ void WebSocketConnectionImpl::onNewMessage(
}
// LOG_TRACE << "new message received: " << message
// << "\n(type=" << (int)type << ")";
messageCallback_(std::move(message), shared_from_this(), type);
messageCallback_(std::move(message), self, type);
}
else
{