================ @@ -0,0 +1,144 @@ +//===-- 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 "Protocol.h" +#include "lldb/Utility/IOObject.h" +#include "lldb/Utility/Status.h" +#include "lldb/lldb-forward.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/Error.h" +#include "llvm/Support/raw_ostream.h" +#include <string> +#include <utility> + +using namespace llvm; +using namespace lldb; +using namespace lldb_private; +using namespace lldb_dap; +using namespace lldb_dap::protocol; + +static Expected<std::string> ReadFull(IOObject *descriptor, size_t length) { + std::string data; + data.resize(length); + auto status = descriptor->Read(data.data(), length); + if (status.Fail()) + return status.takeError(); + return data.substr(0, length); +} + +static Expected<std::string> ReadUntil(IOObject *descriptor, + StringRef delimiter) { + std::string buffer; + buffer.reserve(delimiter.size() + 1); + while (!llvm::StringRef(buffer).ends_with(delimiter)) { + Expected<std::string> next = + ReadFull(descriptor, buffer.empty() ? delimiter.size() : 1); + if (auto Err = next.takeError()) + return std::move(Err); + // '' is returned on EOF. + if (next->empty()) + return buffer; + buffer += *next; + } + return buffer.substr(0, buffer.size() - delimiter.size()); +} + +/// DAP message format +/// ``` +/// Content-Length: (?<length>\d+)\r\n\r\n(?<content>.{\k<length>}) +/// ``` +static const StringLiteral kHeaderContentLength = "Content-Length: "; +static const StringLiteral kHeaderSeparator = "\r\n\r\n"; ---------------- ashgti wrote:
Done. https://github.com/llvm/llvm-project/pull/130026 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits