]> git.sesse.net Git - bmusb/blobdiff - bmusb.cpp
Set libusb timeout to one second, to help shutdown if the thread is started with...
[bmusb] / bmusb.cpp
index 7c2108203f7904d76bdb9de9a49c8c1f3964ae3f..cd4e59c4302b5d6cdba09080cd4b36c7337e7c2a 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -878,7 +878,8 @@ void BMUSBCapture::usb_thread_func()
                printf("couldn't set realtime priority for USB thread: %s\n", strerror(errno));
        }
        while (!should_quit) {
-               int rc = libusb_handle_events(nullptr);
+               timeval sec { 1, 0 };
+               int rc = libusb_handle_events_timeout(nullptr, &sec);
                if (rc != LIBUSB_SUCCESS)
                        break;
        }
@@ -1013,6 +1014,12 @@ libusb_device_handle *open_card(unsigned card_index, libusb_device *dev, string
 
 unsigned BMUSBCapture::num_cards()
 {
+       int rc = libusb_init(nullptr);
+       if (rc < 0) {
+               fprintf(stderr, "Error initializing libusb: %s\n", libusb_error_name(rc));
+               exit(1);
+       }
+
        vector<USBCardDevice> found_cards = find_all_cards();
        unsigned ret = found_cards.size();
        for (size_t i = 0; i < found_cards.size(); ++i) {