| 38 | } |
| 39 | |
| 40 | bool UvRunner::poll() { |
| 41 | if (!running_.load()) { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | char buf[4096]; |
| 46 | ssize_t n; |
| 47 | |
| 48 | while ((n = process_.read(buf, sizeof(buf) - 1)) > 0) { |
| 49 | buf[n] = '\0'; |
| 50 | |
| 51 | if (raw_output_callback_) { |
| 52 | raw_output_callback_(std::string(buf, n)); |
| 53 | } else { |
| 54 | output_buffer_ += std::string(buf, n); |
| 55 | process_buffer(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if (n < 0 || !process_.is_running()) { |
| 60 | // Process finished |
| 61 | if (!raw_output_callback_) { |
| 62 | process_buffer(); |
| 63 | if (!output_buffer_.empty()) { |
| 64 | emit_line(output_buffer_, false); |
| 65 | output_buffer_.clear(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | exit_code_ = process_.wait(); |
| 70 | running_ = false; |
| 71 | complete_ = true; |
| 72 | |
| 73 | LOG_INFO("UV completed with exit code {}", exit_code_); |
| 74 | |
| 75 | if (completion_callback_) { |
| 76 | completion_callback_(exit_code_ == 0, exit_code_); |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | void UvRunner::cancel() { |
| 85 | if (running_.load()) { |
no test coverage detected