From 2a8c13e2ab8ac3f24a0797ae37df16b6c33417ba Mon Sep 17 00:00:00 2001 From: aelray Date: Fri, 18 Jun 2021 21:24:00 +0200 Subject: [PATCH 1/2] fix serial read for windows If serial buffer contained more values than requested by erpc underlying receive `serial_read` got stuck. --- erpc_c/port/erpc_serial.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/erpc_c/port/erpc_serial.cpp b/erpc_c/port/erpc_serial.cpp index 14d05bf2..351bb6e4 100644 --- a/erpc_c/port/erpc_serial.cpp +++ b/erpc_c/port/erpc_serial.cpp @@ -210,18 +210,18 @@ int serial_read(int fd, char *buf, int size) unsigned long bread = 0; char temp[RX_BUF_BYTES] = { 0 }; DWORD errors; - DWORD bytesToRead = 0; + DWORD totalBytesRead = 0; DWORD bytesRead = 0; DWORD ret = 0; - while (bytesToRead != size) + while (totalBytesRead != size) { do { ClearCommError(hCom, &errors, NULL); - if (!ReadFile(hCom, temp, RX_BUF_BYTES - bytesToRead, &bytesRead, &s_readOverlap)) + if (!ReadFile(hCom, temp, size - totalBytesRead, &bytesRead, &s_readOverlap)) { if (GetLastError() == ERROR_IO_PENDING) { @@ -232,23 +232,23 @@ int serial_read(int fd, char *buf, int size) if (!GetOverlappedResult(hCom, &s_readOverlap, &bytesRead, FALSE)) { bytesRead = 0; - bytesToRead = 0; + totalBytesRead = 0; } } else { bytesRead = 0; - bytesToRead = 0; + totalBytesRead = 0; } } else { bytesRead = 0; - bytesToRead = 0; + totalBytesRead = 0; } } - bytesToRead += bytesRead; + totalBytesRead += bytesRead; if (bytesRead) { @@ -256,10 +256,10 @@ int serial_read(int fd, char *buf, int size) buf += bytesRead; } - } while ((bytesRead > 0) && (RX_BUF_BYTES >= bytesToRead)); + } while ((bytesRead > 0) && (size <= RX_BUF_BYTES) && (RX_BUF_BYTES >= totalBytesRead)); } - return bytesToRead; + return totalBytesRead; #else int len = 0; int ret = 0; From 4aaa0c015f34ddfe18e235067e6bba44584fa95f Mon Sep 17 00:00:00 2001 From: aelray Date: Thu, 24 Jun 2021 11:08:13 +0200 Subject: [PATCH 2/2] remove unused variable --- erpc_c/port/erpc_serial.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/erpc_c/port/erpc_serial.cpp b/erpc_c/port/erpc_serial.cpp index 351bb6e4..6411fa91 100644 --- a/erpc_c/port/erpc_serial.cpp +++ b/erpc_c/port/erpc_serial.cpp @@ -207,7 +207,6 @@ int serial_read(int fd, char *buf, int size) { #ifdef _WIN32 HANDLE hCom = (HANDLE)fd; - unsigned long bread = 0; char temp[RX_BUF_BYTES] = { 0 }; DWORD errors; DWORD totalBytesRead = 0;