From: Michael Gernoth Date: Sat, 13 Jul 2013 22:43:29 +0000 (+0200) Subject: only wake the device up when the timeout really expired X-Git-Tag: v0.100~56 X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/hmcfgusb/commitdiff_plain/1e79d00a9f4c2f059c8bd2dc22e601c4ed4065d6 only wake the device up when the timeout really expired --- diff --git a/hmcfgusb.c b/hmcfgusb.c index d8a442f..0857a4b 100644 --- a/hmcfgusb.c +++ b/hmcfgusb.c @@ -393,6 +393,7 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout) { struct timeval tv; int usb_event = 0; + int timed_out = 0; int i; int n; int fd_n; @@ -430,6 +431,7 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout) return -1; } else if (n == 0) { usb_event = 1; + timed_out = 1; } else { for (fd_n = 0; fd_n < dev->n_pfd; fd_n++) { if (dev->pfd[fd_n].revents) { @@ -461,6 +463,9 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout) errno = quit; } + if (timed_out) + errno = ETIMEDOUT; + return -1; } diff --git a/hmland.c b/hmland.c index c50022c..32a1cdf 100644 --- a/hmland.c +++ b/hmland.c @@ -478,11 +478,18 @@ static int comm(int fd_in, int fd_out, int master_socket, int flags) } } else if (fd == -1) { if (errno) { - perror("hmcfgusb_poll"); - quit = 1; - } else { - /* periodically wakeup the device */ - hmcfgusb_send_null_frame(dev, 1); + if (errno != ETIMEDOUT) { + perror("hmcfgusb_poll"); + quit = 1; + } else { + /* periodically wakeup the device */ + hmcfgusb_send_null_frame(dev, 1); + if (wait_for_h) { + memset(out, 0, sizeof(out)); + out[0] = 'K'; + hmcfgusb_send(dev, out, sizeof(out), 1); + } + } } } } diff --git a/hmsniff.c b/hmsniff.c index 1936d5b..ee14800 100644 --- a/hmsniff.c +++ b/hmsniff.c @@ -206,11 +206,13 @@ int main(int argc, char **argv) continue; } else if (fd == -1) { if (errno) { - perror("hmcfgusb_poll"); - break; - } else { - /* periodically wakeup the device */ - hmcfgusb_send_null_frame(dev, 1); + if (errno != ETIMEDOUT) { + perror("hmcfgusb_poll"); + break; + } else { + /* periodically wakeup the device */ + hmcfgusb_send_null_frame(dev, 1); + } } } }