utils: improve ioctl retry
This commit is contained in:
parent
c139a13ec2
commit
8992ae8f5b
@ -86,21 +86,18 @@ uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv)
|
|||||||
|
|
||||||
int ioctl_retried(const char *name, int fd, int request, void *arg)
|
int ioctl_retried(const char *name, int fd, int request, void *arg)
|
||||||
{
|
{
|
||||||
#define MAX_RETRIES 4
|
#define MAX_RETRIES 10
|
||||||
|
#define RETRY_INTERVAL_US 1000
|
||||||
|
|
||||||
int retries = 4;
|
for (int try = 0; try <= MAX_RETRIES; try++) {
|
||||||
int ret = -1;
|
int ret = ioctl(fd, request, arg);
|
||||||
|
|
||||||
while (retries-- > 0) {
|
|
||||||
ret = ioctl(fd, request, arg);
|
|
||||||
if (errno != EINTR && errno != EAGAIN && errno != ETIMEDOUT)
|
if (errno != EINTR && errno != EAGAIN && errno != ETIMEDOUT)
|
||||||
break;
|
return ret;
|
||||||
|
usleep(RETRY_INTERVAL_US);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret && retries <= 0) {
|
LOG_INFO(NULL, "%s: ioctl(%08x, errno=%d) retried %u times", name, request, errno, MAX_RETRIES);
|
||||||
LOG_PERROR(NULL, "%s: ioctl(%08x, errno=%d) retried %u times; giving up", name, request, errno, MAX_RETRIES);
|
return -1;
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *trim(char *s)
|
char *trim(char *s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user