John Harrison 69878f9fa1
[lldb] Refactor JSONTransport own MainLoop read handle. (#179564)
When working with a MainLoop, if the file reaches the EOF it will
immediately fire the read handle callback. We cannot readily determine
if the file is at EOF or if the file is pointing to a socket/pipe that
has consumed all the current data in the buffer but the remote end has
not yet hung up. This is causing JSONTransport to continuously fire the
OnRead callback trigging repeated calls to the
`MessageHandler::OnClose`.

Since MainLoop does not perform the actual read, we need to adjust the
behavior of JSONTransport to fully own the read handle.

This change moves the ownership of the `MainLoop::ReadHandleUP` and
additionally own a reference to the `MainLoop` itself to ensure the loop
outlives the JSONTransport object.

This allows us to remove the handle immediately when we detect an EOF /
hang up has occurred.
2026-02-06 10:07:09 -08:00

30 lines
944 B
C++

//===-- Transport.cpp -----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "Transport.h"
#include "DAPLog.h"
#include "lldb/lldb-forward.h"
#include "llvm/ADT/StringRef.h"
using namespace llvm;
using namespace lldb;
using namespace lldb_private;
namespace lldb_dap {
Transport::Transport(lldb_dap::Log &log, lldb_private::MainLoop &loop,
lldb::IOObjectSP input, lldb::IOObjectSP output)
: HTTPDelimitedJSONTransport(loop, input, output), m_log(log) {}
void Transport::Log(llvm::StringRef message) {
// Emit the message directly, since this log was forwarded.
m_log.Emit(message);
}
} // namespace lldb_dap