From 99cbad2c286b5f60eb32ef02c4af62a0388be7eb Mon Sep 17 00:00:00 2001 From: Adrian Scripca Date: Thu, 27 Apr 2023 16:00:42 +0300 Subject: [PATCH] Fixed borken read --- grbl_communication.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/grbl_communication.cpp b/grbl_communication.cpp index 62fbe36..916e64e 100644 --- a/grbl_communication.cpp +++ b/grbl_communication.cpp @@ -83,7 +83,12 @@ void grbl::tcp_transport::worker() { // anything to read? auto read_bytes = read(fd, buffer, 200); - if (read_bytes > 0) { + if (read_bytes == -1 && (errno == EWOULDBLOCK || errno == EAGAIN)) { + // do nothing + } else if (read_bytes == -1) { + std::cerr << "Failed while reading." << std::endl; + close(); + } else { for (int i = 0; i < read_bytes; i++) { auto is_eol = buffer[i] == '\r' || buffer[i] == '\n'; if (is_eol) { @@ -98,7 +103,7 @@ void grbl::tcp_transport::worker() { } // give some time to others - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } }