summaryrefslogtreecommitdiff
path: root/examples/dpfp.c
diff options
context:
space:
mode:
authorDaniel Drake <dsd@gentoo.org>2008-05-11 20:31:58 +0100
committerDaniel Drake <dsd@gentoo.org>2008-05-11 20:47:27 +0100
commitfec7c84163e25b8f811632828334d75da82bcb16 (patch)
tree9ccdab1835c2396bfe79ecc484328932ff186427 /examples/dpfp.c
parentaeb905fa5d78cdbba80a680aa7a2bb7338f27f65 (diff)
downloadlibusb-fec7c84163e25b8f811632828334d75da82bcb16.tar.gz
Handle hot-unplugging
This involved moving from select() to poll() because there is no way to distinguish usbfs's POLLERR condition with select().
Diffstat (limited to 'examples/dpfp.c')
-rw-r--r--examples/dpfp.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/examples/dpfp.c b/examples/dpfp.c
index a64abdc..7808184 100644
--- a/examples/dpfp.c
+++ b/examples/dpfp.c
@@ -283,6 +283,7 @@ static void cb_irq(struct libusb_transfer *transfer)
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "irq transfer status %d?\n", transfer->status);
do_exit = 2;
+ libusb_free_transfer(transfer);
irq_transfer = NULL;
return;
}
@@ -319,6 +320,7 @@ static void cb_img(struct libusb_transfer *transfer)
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fprintf(stderr, "img transfer status %d?\n", transfer->status);
do_exit = 2;
+ libusb_free_transfer(transfer);
img_transfer = NULL;
return;
}
@@ -431,7 +433,7 @@ int main(void)
r = libusb_claim_interface(devh, 0);
if (r < 0) {
- fprintf(stderr, "usb_claim_interface error %d %s\n", r, strerror(-r));
+ fprintf(stderr, "usb_claim_interface error %d\n", r);
goto out;
}
printf("claimed interface\n");
@@ -468,14 +470,18 @@ int main(void)
}
printf("shutting down...\n");
+
+ if (irq_transfer) {
+ r = libusb_cancel_transfer(irq_transfer);
+ if (r < 0)
+ goto out_deinit;
+ }
- r = libusb_cancel_transfer(irq_transfer);
- if (r < 0)
- goto out_deinit;
-
- r = libusb_cancel_transfer(img_transfer);
- if (r < 0)
- goto out_deinit;
+ if (img_transfer) {
+ r = libusb_cancel_transfer(img_transfer);
+ if (r < 0)
+ goto out_deinit;
+ }
while (irq_transfer || img_transfer)
if (libusb_handle_events() < 0)