From: Nathael Pajani Date: Mon, 14 May 2012 23:21:32 +0000 (+0200) Subject: Added timeout (fixed, 500ms) to read commands X-Git-Tag: v1.0~36 X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=4debe195d2d93f68b6e0d2ba4484c7132c7ee650;p=soft%2Ftools%2Flpctools Added timeout (fixed, 500ms) to read commands --- diff --git a/isp_utils.c b/isp_utils.c index af702d9..950fd95 100644 --- a/isp_utils.c +++ b/isp_utils.c @@ -148,6 +148,7 @@ int isp_serial_read(char* buf, unsigned int buf_size, unsigned int min_read) { int nb = 0; unsigned int count = 0; + unsigned int loops = 0; /* Used to create a timeout */ if (min_read > buf_size) { printf("serial_read: buffer too small for min read value.\n"); @@ -158,6 +159,9 @@ int isp_serial_read(char* buf, unsigned int buf_size, unsigned int min_read) nb = read(serial_fd, &buf[count], (buf_size - count)); if (nb < 0) { if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { + if (loops++ > 100) { + break; /* timeout at 500ms */ + } usleep( 5000 ); continue; }