Browse Source

Do sequential reads in avalon_get_reset to cope with partial reads.

Con Kolivas 13 years ago
parent
commit
ad55fbf906
1 changed files with 10 additions and 7 deletions
  1. 10 7
      driver-avalon.c

+ 10 - 7
driver-avalon.c

@@ -302,7 +302,7 @@ static void avalon_get_reset(int fd, struct avalon_result *ar)
 	int read_amount = AVALON_READ_SIZE;
 	int read_amount = AVALON_READ_SIZE;
 	uint8_t result[AVALON_READ_SIZE];
 	uint8_t result[AVALON_READ_SIZE];
 	struct timeval timeout = {1, 0};
 	struct timeval timeout = {1, 0};
-	ssize_t ret = 0;
+	ssize_t ret = 0, offset = 0;
 	fd_set rd;
 	fd_set rd;
 
 
 	memset(result, 0, AVALON_READ_SIZE);
 	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");
 		applog(LOG_WARNING, "Avalon: Timeout on select in avalon_get_reset");
 		return;
 		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) {
 	if (opt_debug) {
 		applog(LOG_DEBUG, "Avalon: get:");
 		applog(LOG_DEBUG, "Avalon: get:");
 		hexdump((uint8_t *)result, AVALON_READ_SIZE);
 		hexdump((uint8_t *)result, AVALON_READ_SIZE);