Skip to content

Commit facdc77

Browse files
committed
Only apply the Transport::Read timeout to the initial read of the header, once we have the header we should read the full message.
1 parent c183231 commit facdc77

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lldb/tools/lldb-dap/Transport.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/StringRef.h"
1818
#include "llvm/Support/Error.h"
1919
#include "llvm/Support/raw_ostream.h"
20+
#include <optional>
2021
#include <string>
2122
#include <utility>
2223

@@ -30,14 +31,15 @@ using namespace lldb_dap::protocol;
3031
/// encountered, an empty string is returned.
3132
static Expected<std::string>
3233
ReadFull(IOObject &descriptor, size_t length,
33-
const std::chrono::microseconds &timeout) {
34+
std::optional<std::chrono::microseconds> timeout = std::nullopt) {
3435
if (!descriptor.IsValid())
3536
return createStringError("transport output is closed");
3637

3738
#ifndef _WIN32
3839
// FIXME: SelectHelper does not work with NativeFile on Win32.
3940
SelectHelper sh;
40-
sh.SetTimeout(timeout);
41+
if (timeout)
42+
sh.SetTimeout(*timeout);
4143
sh.FDSetRead(descriptor.GetWaitableHandle());
4244
Status status = sh.Select();
4345
if (status.Fail())
@@ -55,7 +57,7 @@ ReadFull(IOObject &descriptor, size_t length,
5557

5658
static Expected<std::string>
5759
ReadUntil(IOObject &descriptor, StringRef delimiter,
58-
const std::chrono::microseconds &timeout) {
60+
std::optional<std::chrono::microseconds> timeout = std::nullopt) {
5961
std::string buffer;
6062
buffer.reserve(delimiter.size() + 1);
6163
while (!llvm::StringRef(buffer).ends_with(delimiter)) {
@@ -104,7 +106,7 @@ Transport::Read(const std::chrono::microseconds &timeout) {
104106
.str());
105107

106108
Expected<std::string> raw_length =
107-
ReadUntil(*input, kHeaderSeparator, timeout);
109+
ReadUntil(*input, kHeaderSeparator);
108110
if (!raw_length)
109111
return raw_length.takeError();
110112
if (raw_length->empty())
@@ -115,7 +117,7 @@ Transport::Read(const std::chrono::microseconds &timeout) {
115117
return createStringError(
116118
formatv("invalid content length {0}", *raw_length).str());
117119

118-
Expected<std::string> raw_json = ReadFull(*input, length, timeout);
120+
Expected<std::string> raw_json = ReadFull(*input, length);
119121
if (!raw_json)
120122
return raw_json.takeError();
121123
// If we got less than the expected number of bytes then we hit EOF.

lldb/tools/lldb-dap/Transport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class Transport {
4242

4343
/// Reads the next Debug Adater Protocol message from the input stream.
4444
///
45+
/// \param timeout[in]
46+
/// A timeout to wait for reading the initial header. Once a message
47+
/// header is recieved, this will block until the full message is
48+
/// read.
49+
///
4550
/// \returns Returns the next protocol message or nullopt if EOF is reached.
4651
llvm::Expected<std::optional<protocol::Message>>
4752
Read(const std::chrono::microseconds &timeout);

0 commit comments

Comments
 (0)