1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-03-13 06:01:03 +00:00

Do sequential reads in avalon_get_reset to cope with partial reads.

This commit is contained in:
Con Kolivas 2013-04-08 11:20:10 +10:00
parent 385f1cd8d4
commit ad55fbf906

View File

@ -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);