diff options
| author | 2009-08-20 00:13:50 +0200 | |
|---|---|---|
| committer | 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) | |||
| 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; |
