17
17
#include " llvm/ADT/StringRef.h"
18
18
#include " llvm/Support/Error.h"
19
19
#include " llvm/Support/raw_ostream.h"
20
+ #include < optional>
20
21
#include < string>
21
22
#include < utility>
22
23
@@ -30,14 +31,15 @@ using namespace lldb_dap::protocol;
30
31
// / encountered, an empty string is returned.
31
32
static Expected<std::string>
32
33
ReadFull (IOObject &descriptor, size_t length,
33
- const std::chrono::microseconds & timeout) {
34
+ std::optional<std:: chrono::microseconds> timeout = std::nullopt ) {
34
35
if (!descriptor.IsValid ())
35
36
return createStringError (" transport output is closed" );
36
37
37
38
#ifndef _WIN32
38
39
// FIXME: SelectHelper does not work with NativeFile on Win32.
39
40
SelectHelper sh;
40
- sh.SetTimeout (timeout);
41
+ if (timeout)
42
+ sh.SetTimeout (*timeout);
41
43
sh.FDSetRead (descriptor.GetWaitableHandle ());
42
44
Status status = sh.Select ();
43
45
if (status.Fail ())
@@ -55,7 +57,7 @@ ReadFull(IOObject &descriptor, size_t length,
55
57
56
58
static Expected<std::string>
57
59
ReadUntil (IOObject &descriptor, StringRef delimiter,
58
- const std::chrono::microseconds & timeout) {
60
+ std::optional<std:: chrono::microseconds> timeout = std::nullopt ) {
59
61
std::string buffer;
60
62
buffer.reserve (delimiter.size () + 1 );
61
63
while (!llvm::StringRef (buffer).ends_with (delimiter)) {
@@ -104,7 +106,7 @@ Transport::Read(const std::chrono::microseconds &timeout) {
104
106
.str ());
105
107
106
108
Expected<std::string> raw_length =
107
- ReadUntil (*input, kHeaderSeparator , timeout );
109
+ ReadUntil (*input, kHeaderSeparator );
108
110
if (!raw_length)
109
111
return raw_length.takeError ();
110
112
if (raw_length->empty ())
@@ -115,7 +117,7 @@ Transport::Read(const std::chrono::microseconds &timeout) {
115
117
return createStringError (
116
118
formatv (" invalid content length {0}" , *raw_length).str ());
117
119
118
- Expected<std::string> raw_json = ReadFull (*input, length, timeout );
120
+ Expected<std::string> raw_json = ReadFull (*input, length);
119
121
if (!raw_json)
120
122
return raw_json.takeError ();
121
123
// If we got less than the expected number of bytes then we hit EOF.
0 commit comments