diff options
author | Nikias Bassen | 2009-08-20 00:13:50 +0200 |
---|---|---|
committer | Hector Martin | 2009-08-21 02:44:46 +0200 |
commit | 886d4014509d64023ecf99b57d0fd39818e85bd4 (patch) | |
tree | 6944841c2518ccb2c9fd62712a974fec6b9b5501 /libusbmuxd/sock_stuff.c | |
parent | 3c19d124c7521aeef6e4f28755c649a58c2860b6 (diff) | |
download | usbmuxd-886d4014509d64023ecf99b57d0fd39818e85bd4.tar.gz usbmuxd-886d4014509d64023ecf99b57d0fd39818e85bd4.tar.bz2 |
sock_stuff: allow 0 timeout (i.e. block until something happens)
Diffstat (limited to 'libusbmuxd/sock_stuff.c')
-rw-r--r-- | libusbmuxd/sock_stuff.c | 16 |
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) int sret; int eagain; struct timeval to; + struct timeval *pto; if (fd <= 0) { if (verbose >= 2) @@ -215,8 +216,13 @@ int check_fd(int fd, fd_mode fdm, unsigned int timeout) FD_ZERO(&fds); FD_SET(fd, &fds); - to.tv_sec = (time_t) (timeout / 1000); - to.tv_usec = (time_t) ((timeout - (to.tv_sec * 1000)) * 1000); + 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; @@ -224,13 +230,13 @@ int check_fd(int fd, fd_mode fdm, unsigned int timeout) eagain = 0; switch (fdm) { case FD_READ: - sret = select(fd + 1, &fds, NULL, NULL, &to); + sret = select(fd + 1, &fds, NULL, NULL, pto); break; case FD_WRITE: - sret = select(fd + 1, NULL, &fds, NULL, &to); + sret = select(fd + 1, NULL, &fds, NULL, pto); break; case FD_EXCEPT: - sret = select(fd + 1, NULL, NULL, &fds, &to); + sret = select(fd + 1, NULL, NULL, &fds, pto); break; default: return -1; |