summaryrefslogtreecommitdiffstats
path: root/libusbmuxd
diff options
context:
space:
mode:
Diffstat (limited to 'libusbmuxd')
-rw-r--r--libusbmuxd/sock_stuff.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/libusbmuxd/sock_stuff.c b/libusbmuxd/sock_stuff.c
index 137375d..e60370c 100644
--- a/libusbmuxd/sock_stuff.c
+++ b/libusbmuxd/sock_stuff.c
@@ -205,6 +205,7 @@ int check_fd(int fd, fd_mode fdm, unsigned int timeout)
205 int sret; 205 int sret;
206 int eagain; 206 int eagain;
207 struct timeval to; 207 struct timeval to;
208 struct timeval *pto;
208 209
209 if (fd <= 0) { 210 if (fd <= 0) {
210 if (verbose >= 2) 211 if (verbose >= 2)
@@ -215,8 +216,13 @@ int check_fd(int fd, fd_mode fdm, unsigned int timeout)
215 FD_ZERO(&fds); 216 FD_ZERO(&fds);
216 FD_SET(fd, &fds); 217 FD_SET(fd, &fds);
217 218
218 to.tv_sec = (time_t) (timeout / 1000); 219 if (timeout > 0) {
219 to.tv_usec = (time_t) ((timeout - (to.tv_sec * 1000)) * 1000); 220 to.tv_sec = (time_t) (timeout / 1000);
221 to.tv_usec = (time_t) ((timeout - (to.tv_sec * 1000)) * 1000);
222 pto = &to;
223 } else {
224 pto = NULL;
225 }
220 226
221 sret = -1; 227 sret = -1;
222 228
@@ -224,13 +230,13 @@ int check_fd(int fd, fd_mode fdm, unsigned int timeout)
224 eagain = 0; 230 eagain = 0;
225 switch (fdm) { 231 switch (fdm) {
226 case FD_READ: 232 case FD_READ:
227 sret = select(fd + 1, &fds, NULL, NULL, &to); 233 sret = select(fd + 1, &fds, NULL, NULL, pto);
228 break; 234 break;
229 case FD_WRITE: 235 case FD_WRITE:
230 sret = select(fd + 1, NULL, &fds, NULL, &to); 236 sret = select(fd + 1, NULL, &fds, NULL, pto);
231 break; 237 break;
232 case FD_EXCEPT: 238 case FD_EXCEPT:
233 sret = select(fd + 1, NULL, NULL, &fds, &to); 239 sret = select(fd + 1, NULL, NULL, &fds, pto);
234 break; 240 break;
235 default: 241 default:
236 return -1; 242 return -1;