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.
3132static Expected<std::string>
3233ReadFull (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
5658static Expected<std::string>
5759ReadUntil (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.
0 commit comments