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. 13
      driver-avalon.c

13
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); do {
if (unlikely(ret != read_amount)) { ret = read(fd, result + offset, read_amount);
applog(LOG_WARNING, "Avalon: Error %d on read, asked for %d got %d in avalon_get_reset", if (unlikely(ret < 0)) {
errno, read_amount, ret); applog(LOG_WARNING, "Avalon: Error %d on read in avalon_get_reset", errno);
return; 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);

Loading…
Cancel
Save