From d2825e00fd43f2fce57014d0ad22b7a985f7d054 Mon Sep 17 00:00:00 2001 From: joerg_wunsch Date: Wed, 11 May 2005 17:09:22 +0000 Subject: [PATCH] Revert the serial_recv() timeout handling as it used to be before my yesterday's changes (i.e. before rev. 1.10 of ser_posix.c), that is, exit(1) in case of a timeout. Previously, the upper layers didn't see the timeout at all. Quite possible that some of these drivers could handle a timeout more intelligently though. At least for the rather sophisticated STK500v2 protocol, I think it should be possible to retry the request. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@460 81a1dc3b-b13d-400b-aceb-764788c761c2 --- avr910.c | 11 ++++++++++- butterfly.c | 11 ++++++++++- stk500.c | 11 ++++++++++- stk500v2.c | 4 +++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/avr910.c b/avr910.c index 7f4883b5..63bd6855 100644 --- a/avr910.c +++ b/avr910.c @@ -52,7 +52,16 @@ static int avr910_send(PROGRAMMER * pgm, char * buf, size_t len) static int avr910_recv(PROGRAMMER * pgm, char * buf, size_t len) { - return serial_recv(pgm->fd, buf, len); + int rv; + + rv = serial_recv(pgm->fd, buf, len); + if (rv < 0) { + fprintf(stderr, + "%s: avr910_recv(): programmer is not responding\n", + progname); + exit(1); + } + return 0; } diff --git a/butterfly.c b/butterfly.c index 43b60f90..0108ab62 100644 --- a/butterfly.c +++ b/butterfly.c @@ -66,9 +66,18 @@ static int butterfly_send(PROGRAMMER * pgm, char * buf, size_t len) static int butterfly_recv(PROGRAMMER * pgm, char * buf, size_t len) { + int rv; + no_show_func_info(); - return serial_recv(pgm->fd, buf, len); + rv = serial_recv(pgm->fd, buf, len); + if (rv < 0) { + fprintf(stderr, + "%s: butterfly_recv(): programmer is not responding\n", + progname); + exit(1); + } + return 0; } diff --git a/stk500.c b/stk500.c index 2852a928..6e3532ad 100644 --- a/stk500.c +++ b/stk500.c @@ -63,7 +63,16 @@ static int stk500_send(PROGRAMMER * pgm, char * buf, size_t len) static int stk500_recv(PROGRAMMER * pgm, char * buf, size_t len) { - return serial_recv(pgm->fd, buf, len); + int rv; + + rv = serial_recv(pgm->fd, buf, len); + if (rv < 0) { + fprintf(stderr, + "%s: stk500_recv(): programmer is not responding\n", + progname); + exit(1); + } + return 0; } diff --git a/stk500v2.c b/stk500v2.c index fa504ca9..fe7f2635 100644 --- a/stk500v2.c +++ b/stk500v2.c @@ -128,7 +128,8 @@ static int stk500v2_recv(PROGRAMMER * pgm, unsigned char msg[], size_t maxsize) tstart = tv.tv_sec; while ( (state != sDONE ) && (!timeout) ) { - serial_recv(pgm->fd, &c, 1); + if (serial_recv(pgm->fd, &c, 1) < 0) + goto timedout; DEBUG("0x%02x ",c); checksum ^= c; @@ -203,6 +204,7 @@ static int stk500v2_recv(PROGRAMMER * pgm, unsigned char msg[], size_t maxsize) gettimeofday(&tv, NULL); tnow = tv.tv_sec; if (tnow-tstart > timeoutval) { // wuff - signed/unsigned/overflow + timedout: fprintf(stderr, "%s: stk500_2_ReceiveMessage(): timeout\n", progname); return -1;