From: Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
Date: Thu, 19 May 2011 22:47:16 +0200
Subject: Register the pollfds created before the handlers are registered

Patch forwarded (and applied) upstream in
https://forge.ocamlcore.org/plugins/scmdarcs/cgi-bin/darcsweb.cgi?r=ocaml-usb/ocaml-usb;a=commit;h=20110519163209-c41ad-dd065e2dac213cf793b1cf9a3ee193bea88177cc.gz
https://forge.ocamlcore.org/plugins/scmdarcs/cgi-bin/darcsweb.cgi?r=ocaml-usb/ocaml-usb;a=commit;h=20110519193825-c41ad-4b108fe46b693e4b262442602c8f761bd5bedbd4.gz
---
 src/usb_stubs.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/usb_stubs.c b/src/usb_stubs.c
index b9f0e9d..a072c7f 100644
--- a/src/usb_stubs.c
+++ b/src/usb_stubs.c
@@ -140,9 +140,24 @@ static void ml_usb_remove_pollfd(int fd, void *user_data)
 
 CAMLprim value ml_usb_init()
 {
+
+  const struct libusb_pollfd** pollfds = NULL;
+
+  int i = 0;
+
   int res = libusb_init(NULL);
   if (res) ml_usb_error(res, "init");
 
+  pollfds = libusb_get_pollfds(NULL);
+
+
+  if (pollfds) {
+    for (i = 0; pollfds[i] != NULL; i++ ) {
+      ml_usb_add_pollfd(pollfds[i]->fd, pollfds[i]->events, NULL);
+    }
+    free(pollfds);
+  }
+
   libusb_set_pollfd_notifiers(NULL,
                               ml_usb_add_pollfd,
                               ml_usb_remove_pollfd,
-- 
