DevTools server callbacks can outlive the server when deferred work is queued during connection shutdown. Capture weak pointers for those tasks and clear socket callbacks while the server is being destroyed so later actor cleanup cannot touch freed state. Add protocol coverage that destroys a server with deferred actor cleanup pending, before adding the style-rule actor path that depends on this.
41 lines
932 B
C++
41 lines
932 B
C++
/*
|
|
* Copyright (c) 2025, Tim Flynn <trflynn89@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/Function.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/RefCounted.h>
|
|
#include <AK/Weakable.h>
|
|
#include <LibCore/Socket.h>
|
|
#include <LibDevTools/Forward.h>
|
|
|
|
namespace DevTools {
|
|
|
|
class DEVTOOLS_API Connection
|
|
: public RefCounted<Connection>
|
|
, public Weakable<Connection> {
|
|
public:
|
|
static NonnullRefPtr<Connection> create(NonnullOwnPtr<Core::BufferedTCPSocket>);
|
|
~Connection();
|
|
|
|
Function<void()> on_connection_closed;
|
|
Function<void(JsonObject)> on_message_received;
|
|
|
|
void send_message(JsonValue const&);
|
|
|
|
private:
|
|
explicit Connection(NonnullOwnPtr<Core::BufferedTCPSocket>);
|
|
|
|
ErrorOr<void> on_ready_to_read();
|
|
ErrorOr<JsonValue> read_message();
|
|
|
|
NonnullOwnPtr<Core::BufferedTCPSocket> m_socket;
|
|
};
|
|
|
|
}
|