Commit ad55fbf906eec4b11a9cc9a994e0d77d5729cbec

Con Kolivas 2013-04-08T11:20:10

Do sequential reads in avalon_get_reset to cope with partial reads.

diff --git a/driver-avalon.c b/driver-avalon.c
index f93b839..4af8f9c 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -302,7 +302,7 @@ static void avalon_get_reset(int fd, struct avalon_result *ar)
 	int read_amount = AVALON_READ_SIZE;
 	uint8_t result[AVALON_READ_SIZE];
 	struct timeval timeout = {1, 0};
-	ssize_t ret = 0;
+	ssize_t ret = 0, offset = 0;
 	fd_set rd;
 
 	memset(result, 0, AVALON_READ_SIZE);
@@ -318,12 +318,15 @@ static void avalon_get_reset(int fd, struct avalon_result *ar)
 		applog(LOG_WARNING, "Avalon: Timeout on select in avalon_get_reset");
 		return;
 	}
-	ret = read(fd, result, read_amount);
-	if (unlikely(ret != read_amount)) {
-		applog(LOG_WARNING, "Avalon: Error %d on read, asked for %d got %d in avalon_get_reset",
-		       errno, read_amount, ret);
-		return;
-	}
+	do {
+		ret = read(fd, result + offset, read_amount);
+		if (unlikely(ret < 0)) {
+			applog(LOG_WARNING, "Avalon: Error %d on read in avalon_get_reset", errno);
+			return;
+		}
+		read_amount -= ret;
+		offset += ret;
+	} while (read_amount > 0);
 	if (opt_debug) {
 		applog(LOG_DEBUG, "Avalon: get:");
 		hexdump((uint8_t *)result, AVALON_READ_SIZE);