]> cvs.zerfleddert.de Git - hmcfgusb/blobdiff - hmcfgusb.c
data buffer is freed by libusb_free_transfer
[hmcfgusb] / hmcfgusb.c
index c3fb60b5c74d3d24ccad414551aa58412e4fe65f..bfe0369d28ca865deb0840219ed307eb2782bd7f 100644 (file)
@@ -152,16 +152,12 @@ int hmcfgusb_send(struct hmcfgusb_dev *usbdev, unsigned char* send_data, int len
                return 0;
        }
 
-       usleep(1000);
-
        if (done) {
                err = libusb_interrupt_transfer(usbdev->usb_devh, EP_OUT, send_data, 0, &cnt, USB_TIMEOUT);
                if (err) {
                        fprintf(stderr, "Can't send data: %s\n", usb_strerror(err));
                        return 0;
                }
-
-               usleep(1000);
        }
 
        return 1;
@@ -195,7 +191,6 @@ static struct libusb_transfer *hmcfgusb_prepare_int(libusb_device_handle *devh,
        if (err != 0) {
                fprintf(stderr, "Can't submit transfer: %s\n", usb_strerror(err));
                libusb_free_transfer(transfer);
-               free(data_buf);
                return NULL;
        }
 
@@ -321,6 +316,8 @@ struct hmcfgusb_dev *hmcfgusb_init(hmcfgusb_cb_fn cb, void *data)
 
        dev->n_pfd = dev->n_usb_pfd;
 
+       quit = 0;
+
        return dev;
 }
 
@@ -374,6 +371,7 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout)
                n = poll(dev->pfd, dev->n_pfd, tv.tv_sec * 1000);
                if (n < 0) {
                        perror("poll");
+                       errno = 0;
                        return -1;
                } else if (n == 0) {
                        usb_event = 1;
@@ -384,6 +382,7 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout)
                                                usb_event = 1;
                                                break;
                                        } else {
+                                               errno = 0;
                                                return dev->pfd[fd_n].fd;
                                        }
                                }
@@ -401,8 +400,11 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout)
                }
        }
 
-       if (quit)
+       errno = 0;
+       if (quit) {
+               fprintf(stderr, "closing device-connection due to error %d\n", quit);
                errno = quit;
+       }
 
        return -1;
 }
Impressum, Datenschutz