Browse Source

avalon: Simplify avalon_get_result by using avalon_gets

Luke Dashjr 12 years ago
parent
commit
45c81f17b1
1 changed files with 7 additions and 30 deletions
  1. 7 30
      driver-avalon.c

+ 7 - 30
driver-avalon.c

@@ -305,39 +305,16 @@ static bool avalon_decode_nonce(struct thr_info *thr, struct avalon_result *ar,
 
 
 static void avalon_get_reset(int fd, struct avalon_result *ar)
 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, offset = 0;
-	fd_set rd;
-
-	memset(result, 0, AVALON_READ_SIZE);
+	int ret;
+	const int read_count = AVALON_RESET_FAULT_DECISECONDS * AVALON_TIME_FACTOR;
+	
 	memset(ar, 0, AVALON_READ_SIZE);
 	memset(ar, 0, AVALON_READ_SIZE);
-	FD_ZERO(&rd);
-	FD_SET(fd, &rd);
-	ret = select(fd + 1, &rd, NULL, NULL, &timeout);
-	if (unlikely(ret < 0)) {
-		applog(LOG_WARNING, "Avalon: Error %d on select in avalon_get_reset", errno);
-		return;
-	}
-	if (!ret) {
-		applog(LOG_WARNING, "Avalon: Timeout on select in avalon_get_reset");
-		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) {
+	ret = avalon_gets(fd, (uint8_t*)ar, read_count, NULL, NULL);
+	
+	if (ret == AVA_GETS_OK && opt_debug) {
 		applog(LOG_DEBUG, "Avalon: get:");
 		applog(LOG_DEBUG, "Avalon: get:");
-		hexdump((uint8_t *)result, AVALON_READ_SIZE);
+		hexdump((uint8_t *)ar, AVALON_READ_SIZE);
 	}
 	}
-	memcpy((uint8_t *)ar, result, AVALON_READ_SIZE);
 }
 }
 
 
 static int avalon_reset(int fd, struct avalon_result *ar)
 static int avalon_reset(int fd, struct avalon_result *ar)