================ @@ -777,28 +798,134 @@ llvm::Error DAP::Disconnect(bool terminateDebuggee) { return ToError(error); } +template <typename T> +static std::optional<T> getArgumentsIfRequest(const protocol::Message &pm, + llvm::StringLiteral command) { + auto *const req = std::get_if<protocol::Request>(&pm); + if (!req || req->command != command) + return std::nullopt; + + T args; + llvm::json::Path::Root root; + if (!fromJSON(req->arguments, args, root)) { + return std::nullopt; + } + + return std::move(args); +} + llvm::Error DAP::Loop() { - auto cleanup = llvm::make_scope_exit([this]() { + std::deque<protocol::Message> queue; + std::condition_variable queue_cv; + std::mutex queue_mutex; + std::future<llvm::Error> queue_reader = std::async([&]() -> llvm::Error { + llvm::set_thread_name(transport.GetClientName() + ".transport_handler"); + auto cleanup = llvm::make_scope_exit([&]() { + // Ensure we're marked as disconnecting when the reader exits. + disconnecting = true; + queue_cv.notify_all(); + }); + + while (!disconnecting) { + llvm::Expected<std::optional<protocol::Message>> next = + transport.Read(std::chrono::seconds(1)); + bool timeout = false; + if (llvm::Error Err = llvm::handleErrors( + next.takeError(), + [&](std::unique_ptr<llvm::StringError> Err) -> llvm::Error { ---------------- JDevlieghere wrote:
Do we only want to handle StringError? ```suggestion [&](std::unique_ptr<llvm::Error> Err) -> llvm::Error { ``` https://github.com/llvm/llvm-project/pull/130169 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits