Browse Source

Do sequential reads in avalon_get_reset to cope with partial reads.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
ad55fbf906
  1. 17
      driver-avalon.c

17
driver-avalon.c

@ -302,7 +302,7 @@ static void avalon_get_reset(int fd, struct avalon_result *ar) @@ -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) @@ -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);

Loading…
Cancel
Save