================ @@ -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())); + + return result; } -Status PipePosix::WriteWithTimeout(const void *buf, size_t size, - const std::chrono::microseconds &timeout, - size_t &bytes_written) { +llvm::Expected<size_t> PipePosix::Write(const void *buf, size_t size, + const Timeout<std::micro> &timeout) { std::lock_guard<std::mutex> guard(m_write_mutex); - bytes_written = 0; if (!CanWriteUnlocked()) - return Status(EINVAL, eErrorTypePOSIX); + return llvm::errorCodeToError( + std::make_error_code(std::errc::invalid_argument)); const int fd = GetWriteFileDescriptorUnlocked(); SelectHelper select_helper; - select_helper.SetTimeout(timeout); + if (timeout) + select_helper.SetTimeout(*timeout); select_helper.FDSetWrite(fd); - Status error; - while (error.Success()) { - error = select_helper.Select(); - if (error.Success()) { - auto result = ::write(fd, static_cast<const char *>(buf) + bytes_written, - size - bytes_written); - if (result != -1) { - bytes_written += result; - if (bytes_written == size) - break; - } else if (errno == EINTR) { - continue; - } else { - error = Status::FromErrno(); - } - } - } - return error; + if (llvm::Error error = select_helper.Select().takeError()) + return error; + + ssize_t result = ::write(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