libusb10.c (d94d94e2c06b4331f706a3b4eca058041294ea05) | libusb10.c (aa87aa52326be7b726664dba65e91ec3d8160f48) |
---|---|
1/* $FreeBSD$ */ 2/*- 3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 4 * 5 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 6 * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 102 unchanged lines hidden (view full) --- 111 112 flags = fcntl(f, F_GETFL, NULL); 113 if (flags == -1) 114 return; 115 flags |= O_NONBLOCK; 116 fcntl(f, F_SETFL, flags); 117} 118 | 1/* $FreeBSD$ */ 2/*- 3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 4 * 5 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 6 * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 102 unchanged lines hidden (view full) --- 111 112 flags = fcntl(f, F_GETFL, NULL); 113 if (flags == -1) 114 return; 115 flags |= O_NONBLOCK; 116 fcntl(f, F_SETFL, flags); 117} 118 |
119static void 120libusb10_wakeup_event_loop(libusb_context *ctx) | 119void 120libusb_interrupt_event_handler(libusb_context *ctx) |
121{ | 121{ |
122 uint8_t dummy = 0; | 122 uint8_t dummy; |
123 int err; 124 | 123 int err; 124 |
125 if (ctx == NULL) 126 return; 127 128 dummy = 0; |
|
125 err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); 126 if (err < (int)sizeof(dummy)) { 127 /* ignore error, if any */ 128 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "Waking up event loop failed!"); 129 } 130} 131 132int --- 407 unchanged lines hidden (view full) --- 540 CTX_LOCK(ctx); 541 dev->device_is_gone = 0; 542 CTX_UNLOCK(ctx); 543 544 libusb10_add_pollfd(ctx, &dev->dev_poll, pdev, libusb20_dev_get_fd(pdev), POLLIN | 545 POLLOUT | POLLRDNORM | POLLWRNORM); 546 547 /* make sure our event loop detects the new device */ | 129 err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); 130 if (err < (int)sizeof(dummy)) { 131 /* ignore error, if any */ 132 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "Waking up event loop failed!"); 133 } 134} 135 136int --- 407 unchanged lines hidden (view full) --- 544 CTX_LOCK(ctx); 545 dev->device_is_gone = 0; 546 CTX_UNLOCK(ctx); 547 548 libusb10_add_pollfd(ctx, &dev->dev_poll, pdev, libusb20_dev_get_fd(pdev), POLLIN | 549 POLLOUT | POLLRDNORM | POLLWRNORM); 550 551 /* make sure our event loop detects the new device */ |
548 libusb10_wakeup_event_loop(ctx); | 552 libusb_interrupt_event_handler(ctx); |
549 550 *devh = pdev; 551 552 return (0); 553} 554 555libusb_device_handle * 556libusb_open_device_with_vid_pid(libusb_context *ctx, uint16_t vendor_id, --- 52 unchanged lines hidden (view full) --- 609 libusb10_remove_pollfd(ctx, &dev->dev_poll); 610 611 libusb20_dev_close(pdev); 612 613 /* unref will free the "pdev" when the refcount reaches zero */ 614 libusb_unref_device(dev); 615 616 /* make sure our event loop detects the closed device */ | 553 554 *devh = pdev; 555 556 return (0); 557} 558 559libusb_device_handle * 560libusb_open_device_with_vid_pid(libusb_context *ctx, uint16_t vendor_id, --- 52 unchanged lines hidden (view full) --- 613 libusb10_remove_pollfd(ctx, &dev->dev_poll); 614 615 libusb20_dev_close(pdev); 616 617 /* unref will free the "pdev" when the refcount reaches zero */ 618 libusb_unref_device(dev); 619 620 /* make sure our event loop detects the closed device */ |
617 libusb10_wakeup_event_loop(ctx); | 621 libusb_interrupt_event_handler(ctx); |
618} 619 620libusb_device * 621libusb_get_device(struct libusb20_device *pdev) 622{ 623 if (pdev == NULL) 624 return (NULL); 625 return ((libusb_device *)pdev->privLuData); --- 812 unchanged lines hidden (view full) --- 1438 goto failure; 1439 } 1440 libusb20_tr_start(pxfer0); 1441 return; 1442 1443failure: 1444 libusb10_complete_transfer(pxfer0, sxfer, LIBUSB_TRANSFER_ERROR); 1445 /* make sure our event loop spins the done handler */ | 622} 623 624libusb_device * 625libusb_get_device(struct libusb20_device *pdev) 626{ 627 if (pdev == NULL) 628 return (NULL); 629 return ((libusb_device *)pdev->privLuData); --- 812 unchanged lines hidden (view full) --- 1442 goto failure; 1443 } 1444 libusb20_tr_start(pxfer0); 1445 return; 1446 1447failure: 1448 libusb10_complete_transfer(pxfer0, sxfer, LIBUSB_TRANSFER_ERROR); 1449 /* make sure our event loop spins the done handler */ |
1446 libusb10_wakeup_event_loop(dev->ctx); | 1450 libusb_interrupt_event_handler(dev->ctx); |
1447} 1448 1449/* The following function must be called unlocked */ 1450 1451int 1452libusb_submit_transfer(struct libusb_transfer *uxfer) 1453{ 1454 struct libusb20_transfer *pxfer0; --- 95 unchanged lines hidden (view full) --- 1550 retval = LIBUSB_ERROR_NOT_FOUND; 1551 } else if (sxfer->entry.tqe_prev != NULL) { 1552 /* we are lucky - transfer is on a queue */ 1553 TAILQ_REMOVE(&dev->tr_head, sxfer, entry); 1554 sxfer->entry.tqe_prev = NULL; 1555 libusb10_complete_transfer(NULL, 1556 sxfer, LIBUSB_TRANSFER_CANCELLED); 1557 /* make sure our event loop spins the done handler */ | 1451} 1452 1453/* The following function must be called unlocked */ 1454 1455int 1456libusb_submit_transfer(struct libusb_transfer *uxfer) 1457{ 1458 struct libusb20_transfer *pxfer0; --- 95 unchanged lines hidden (view full) --- 1554 retval = LIBUSB_ERROR_NOT_FOUND; 1555 } else if (sxfer->entry.tqe_prev != NULL) { 1556 /* we are lucky - transfer is on a queue */ 1557 TAILQ_REMOVE(&dev->tr_head, sxfer, entry); 1558 sxfer->entry.tqe_prev = NULL; 1559 libusb10_complete_transfer(NULL, 1560 sxfer, LIBUSB_TRANSFER_CANCELLED); 1561 /* make sure our event loop spins the done handler */ |
1558 libusb10_wakeup_event_loop(dev->ctx); | 1562 libusb_interrupt_event_handler(dev->ctx); |
1559 } else if (pxfer0 == NULL || pxfer1 == NULL) { 1560 /* not started */ 1561 retval = LIBUSB_ERROR_NOT_FOUND; 1562 } else if (libusb20_tr_get_priv_sc1(pxfer0) == sxfer) { 1563 libusb10_complete_transfer(pxfer0, 1564 sxfer, LIBUSB_TRANSFER_CANCELLED); 1565 if (dev->device_is_gone != 0) { 1566 /* clear transfer pointer */ 1567 libusb20_tr_set_priv_sc1(pxfer0, NULL); 1568 /* make sure our event loop spins the done handler */ | 1563 } else if (pxfer0 == NULL || pxfer1 == NULL) { 1564 /* not started */ 1565 retval = LIBUSB_ERROR_NOT_FOUND; 1566 } else if (libusb20_tr_get_priv_sc1(pxfer0) == sxfer) { 1567 libusb10_complete_transfer(pxfer0, 1568 sxfer, LIBUSB_TRANSFER_CANCELLED); 1569 if (dev->device_is_gone != 0) { 1570 /* clear transfer pointer */ 1571 libusb20_tr_set_priv_sc1(pxfer0, NULL); 1572 /* make sure our event loop spins the done handler */ |
1569 libusb10_wakeup_event_loop(dev->ctx); | 1573 libusb_interrupt_event_handler(dev->ctx); |
1570 } else { 1571 libusb20_tr_stop(pxfer0); 1572 /* make sure the queue doesn't stall */ 1573 libusb10_submit_transfer_sub(devh, endpoint); 1574 } 1575 } else if (libusb20_tr_get_priv_sc1(pxfer1) == sxfer) { 1576 libusb10_complete_transfer(pxfer1, 1577 sxfer, LIBUSB_TRANSFER_CANCELLED); 1578 /* check if handle is still active */ 1579 if (dev->device_is_gone != 0) { 1580 /* clear transfer pointer */ 1581 libusb20_tr_set_priv_sc1(pxfer1, NULL); 1582 /* make sure our event loop spins the done handler */ | 1574 } else { 1575 libusb20_tr_stop(pxfer0); 1576 /* make sure the queue doesn't stall */ 1577 libusb10_submit_transfer_sub(devh, endpoint); 1578 } 1579 } else if (libusb20_tr_get_priv_sc1(pxfer1) == sxfer) { 1580 libusb10_complete_transfer(pxfer1, 1581 sxfer, LIBUSB_TRANSFER_CANCELLED); 1582 /* check if handle is still active */ 1583 if (dev->device_is_gone != 0) { 1584 /* clear transfer pointer */ 1585 libusb20_tr_set_priv_sc1(pxfer1, NULL); 1586 /* make sure our event loop spins the done handler */ |
1583 libusb10_wakeup_event_loop(dev->ctx); | 1587 libusb_interrupt_event_handler(dev->ctx); |
1584 } else { 1585 libusb20_tr_stop(pxfer1); 1586 /* make sure the queue doesn't stall */ 1587 libusb10_submit_transfer_sub(devh, endpoint); 1588 } 1589 } else { 1590 /* not started */ 1591 retval = LIBUSB_ERROR_NOT_FOUND; --- 154 unchanged lines hidden --- | 1588 } else { 1589 libusb20_tr_stop(pxfer1); 1590 /* make sure the queue doesn't stall */ 1591 libusb10_submit_transfer_sub(devh, endpoint); 1592 } 1593 } else { 1594 /* not started */ 1595 retval = LIBUSB_ERROR_NOT_FOUND; --- 154 unchanged lines hidden --- |