diff options
author | Nikias Bassen | 2019-05-21 01:31:35 +0200 |
---|---|---|
committer | Nikias Bassen | 2019-05-21 01:31:35 +0200 |
commit | cf265a8cf3059b34209cdef8afb3b77246614e68 (patch) | |
tree | 570846765b32e2b42b27fcc8c0032e45180c3290 | |
parent | 873252dc8b4e469c7dc692064ac616104fca5f65 (diff) | |
download | libusbmuxd-cf265a8cf3059b34209cdef8afb3b77246614e68.tar.gz libusbmuxd-cf265a8cf3059b34209cdef8afb3b77246614e68.tar.bz2 |
socket: Move initialization of timeval structure into retry loop in socket_check_fd()
Depending on the platform, select() may modify the timeval structure to
indicate the amount left on the timer, so we reset the timeout before calling
select() again. Thanks to sctol for reporting.
-rw-r--r-- | common/socket.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/common/socket.c b/common/socket.c index 1a7fe8d..9ff138b 100644 --- a/common/socket.c +++ b/common/socket.c @@ -365,17 +365,16 @@ int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout) FD_ZERO(&fds); FD_SET(fd, &fds); - if (timeout > 0) { - to.tv_sec = (time_t) (timeout / 1000); - to.tv_usec = (time_t) ((timeout - (to.tv_sec * 1000)) * 1000); - pto = &to; - } else { - pto = NULL; - } - sret = -1; do { + if (timeout > 0) { + to.tv_sec = (time_t) (timeout / 1000); + to.tv_usec = (time_t) ((timeout - (to.tv_sec * 1000)) * 1000); + pto = &to; + } else { + pto = NULL; + } eagain = 0; switch (fdm) { case FDM_READ: |