[Lldb-commits] [lldb] [lldb] Refactoring JSONTransport into an abstract RPC Message Handler and transport layer. (PR #153121)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 18 05:01:56 PDT 2025
================
@@ -54,112 +50,226 @@ class TransportUnhandledContentsError
std::string m_unhandled_contents;
};
-class TransportInvalidError : public llvm::ErrorInfo<TransportInvalidError> {
+/// A transport is responsible for maintaining the connection to a client
+/// application, and reading/writing structured messages to it.
+///
+/// Transports have limited thread safety requirements:
+/// - Messages will not be sent concurrently.
+/// - Messages MAY be sent while Run() is reading, or its callback is active.
+template <typename Req, typename Resp, typename Evt> class Transport {
public:
- static char ID;
-
- TransportInvalidError() = default;
+ using Message = std::variant<Req, Resp, Evt>;
+
+ virtual ~Transport() = default;
+
+ /// Sends an event, a message that does not require a response.
+ virtual llvm::Error Event(const Evt &) = 0;
+ /// Sends a request, a message that expects a response.
+ virtual llvm::Error Request(const Req &) = 0;
+ /// Sends a response to a specific request.
+ virtual llvm::Error Response(const Resp &) = 0;
+
+ /// Implemented to handle incoming messages. (See Run() below).
+ class MessageHandler {
+ public:
+ virtual ~MessageHandler() = default;
+ /// Called when an event is received.
+ virtual void OnEvent(const Evt &) = 0;
+ /// Called when a request is received.
+ virtual void OnRequest(const Req &) = 0;
+ /// Called when a response is received.
+ virtual void OnResponse(const Resp &) = 0;
+
+ /// Called when an error occurs while reading from the transport.
+ ///
+ /// NOTE: This does *NOT* indicate that a specific request failed, but that
+ /// there was an error in the underlying transport.
+ virtual void OnError(MainLoopBase &, llvm::Error) = 0;
----------------
labath wrote:
It's kinda weird that this is the only method that takes a mainloop argument. FWICS, this is only needed for the test as the real implementation holds a MainLoop variable anyway. Could the test version do the same?
https://github.com/llvm/llvm-project/pull/153121
More information about the lldb-commits
mailing list