only wake the device up when the timeout really expired
authorMichael Gernoth <michael@gernoth.net>
Sat, 13 Jul 2013 22:43:29 +0000 (00:43 +0200)
committerMichael Gernoth <michael@gernoth.net>
Sat, 13 Jul 2013 22:43:29 +0000 (00:43 +0200)
hmcfgusb.c
hmland.c
hmsniff.c

index d8a442f..0857a4b 100644 (file)
@@ -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;
 }
 
index c50022c..32a1cdf 100644 (file)
--- 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);
+                                       }
+                               }
                        }
                }
        }
index 1936d5b..ee14800 100644 (file)
--- 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);
+                                       }
                                }
                        }
                }
Impressum, Datenschutz