================ @@ -300,70 +304,51 @@ void PipePosix::CloseWriteFileDescriptorUnlocked() { } } -Status PipePosix::ReadWithTimeout(void *buf, size_t size, - const std::chrono::microseconds &timeout, - size_t &bytes_read) { +llvm::Expected<size_t> PipePosix::Read(void *buf, size_t size, + const Timeout<std::micro> &timeout) { std::lock_guard<std::mutex> guard(m_read_mutex); - bytes_read = 0; if (!CanReadUnlocked()) - return Status(EINVAL, eErrorTypePOSIX); + return llvm::errorCodeToError( + std::make_error_code(std::errc::invalid_argument)); const int fd = GetReadFileDescriptorUnlocked(); SelectHelper select_helper; - select_helper.SetTimeout(timeout); + if (timeout) + select_helper.SetTimeout(*timeout); select_helper.FDSetRead(fd); - Status error; - while (error.Success()) { - error = select_helper.Select(); - if (error.Success()) { - auto result = - ::read(fd, static_cast<char *>(buf) + bytes_read, size - bytes_read); - if (result != -1) { - bytes_read += result; - if (bytes_read == size || result == 0) - break; - } else if (errno == EINTR) { - continue; - } else { - error = Status::FromErrno(); - break; - } - } - } - return error; + if (llvm::Error error = select_helper.Select().takeError()) + return error; + + ssize_t result = ::read(fd, buf, size); + if (result == -1) + return llvm::errorCodeToError( + std::error_code(errno, std::generic_category())); ---------------- ashgti wrote:
Should we check for EINTR? (or RetryAfterSignal)? https://github.com/llvm/llvm-project/pull/128719 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits