]> cvs.zerfleddert.de Git - hmcfgusb/commitdiff
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 d8a442f690a04bba9d368c4c4340b54311e2e64b..0857a4b3634f5ac9dee153d051c8074a0b298a5c 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 c50022c8225effc7a8814e50930bddc1f10578f4..32a1cdf16cbf8c13a7f77bd4fa4037cb19eb60a5 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 1936d5bd0d53dbd306cb983084bf3d1cb5dc4070..ee148006a87a3add07d80ca3c3ba2168da583022 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