Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVojtech Kral <vojtech@kral.hk>2018-05-16 15:42:36 +0300
committerVojtech Kral <vojtech@kral.hk>2018-05-21 19:58:22 +0300
commit404fdbcfdf52ffd91db09549c26bf6aa2377e974 (patch)
tree3abae2023dc43c7ff45b83a2138fa15ca1e9d5b5 /xs/src/avrdude/ser_posix.c
parent97b3c38148d291f5ca0513c8a1ca2542760a9a56 (diff)
avrdude: Fixes in error handling
Diffstat (limited to 'xs/src/avrdude/ser_posix.c')
-rw-r--r--xs/src/avrdude/ser_posix.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/xs/src/avrdude/ser_posix.c b/xs/src/avrdude/ser_posix.c
index af7c1fbc7..e71c40179 100644
--- a/xs/src/avrdude/ser_posix.c
+++ b/xs/src/avrdude/ser_posix.c
@@ -47,6 +47,7 @@
#include "libavrdude.h"
long serial_recv_timeout = 5000; /* ms */
+#define MAX_ZERO_READS 512
struct baud_mapping {
long baud;
@@ -363,6 +364,7 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
int rc;
unsigned char * p = buf;
size_t len = 0;
+ unsigned zero_reads = 0;
timeout.tv_sec = serial_recv_timeout / 1000L;
timeout.tv_usec = (serial_recv_timeout % 1000L) * 1000;
@@ -397,9 +399,18 @@ static int ser_recv(union filedescriptor *fd, unsigned char * buf, size_t buflen
avrdude_message(MSG_INFO, "%s: ser_recv(): read error: %s\n",
progname, strerror(errno));
return -1;
+ } else if (rc == 0) {
+ zero_reads++;
+ if (zero_reads > MAX_ZERO_READS) {
+ avrdude_message(MSG_NOTICE2, "%s: ser_recv(): programmer is not responding (too many zero reads)\n",
+ progname);
+ return -1;
+ }
+ } else {
+ zero_reads = 0;
+ p += rc;
+ len += rc;
}
- p += rc;
- len += rc;
}
p = buf;
@@ -435,6 +446,7 @@ static int ser_drain(union filedescriptor *fd, int display)
int nfds;
int rc;
unsigned char buf;
+ unsigned zero_reads = 0;
timeout.tv_sec = 0;
timeout.tv_usec = 250000;
@@ -472,6 +484,15 @@ static int ser_drain(union filedescriptor *fd, int display)
avrdude_message(MSG_INFO, "%s: ser_drain(): read error: %s\n",
progname, strerror(errno));
return -1;
+ } else if (rc == 0) {
+ zero_reads++;
+ if (zero_reads > MAX_ZERO_READS) {
+ avrdude_message(MSG_NOTICE2, "%s: ser_drain(): programmer is not responding (too many zero reads)\n",
+ progname);
+ return -1;
+ }
+ } else {
+ zero_reads = 0;
}
if (display) {
avrdude_message(MSG_INFO, "%02x ", buf);