View | Details | Raw Unified | Return to bug 231076 | Differences between
and this patch

Collapse All | Expand All

(-)lib/libusb/libusb10.c (-31 / +45 lines)
Lines 114-119 Link Here
114
	fcntl(f, F_SETFL, flags);
114
	fcntl(f, F_SETFL, flags);
115
}
115
}
116
116
117
static void
118
libusb10_wakeup_event_loop(libusb_context *ctx)
119
{
120
	uint8_t dummy = 0;
121
	int err;
122
123
	err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
124
	if (err < (int)sizeof(dummy)) {
125
		/* ignore error, if any */
126
		DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "Waking up event loop failed!");
127
	}
128
}
129
117
int
130
int
118
libusb_init(libusb_context **context)
131
libusb_init(libusb_context **context)
119
{
132
{
Lines 484-490 Link Here
484
{
497
{
485
	libusb_context *ctx = dev->ctx;
498
	libusb_context *ctx = dev->ctx;
486
	struct libusb20_device *pdev = dev->os_priv;
499
	struct libusb20_device *pdev = dev->os_priv;
487
	uint8_t dummy;
488
	int err;
500
	int err;
489
501
490
	if (devh == NULL)
502
	if (devh == NULL)
Lines 506-517 Link Here
506
	    POLLOUT | POLLRDNORM | POLLWRNORM);
518
	    POLLOUT | POLLRDNORM | POLLWRNORM);
507
519
508
	/* make sure our event loop detects the new device */
520
	/* make sure our event loop detects the new device */
509
	dummy = 0;
521
	libusb10_wakeup_event_loop(ctx);
510
	err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
522
511
	if (err < (int)sizeof(dummy)) {
512
		/* ignore error, if any */
513
		DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_open write failed!");
514
	}
515
	*devh = pdev;
523
	*devh = pdev;
516
524
517
	return (0);
525
	return (0);
Lines 564-571 Link Here
564
{
572
{
565
	libusb_context *ctx;
573
	libusb_context *ctx;
566
	struct libusb_device *dev;
574
	struct libusb_device *dev;
567
	uint8_t dummy;
568
	int err;
569
575
570
	if (pdev == NULL)
576
	if (pdev == NULL)
571
		return;			/* be NULL safe */
577
		return;			/* be NULL safe */
Lines 581-592 Link Here
581
	libusb_unref_device(dev);
587
	libusb_unref_device(dev);
582
588
583
	/* make sure our event loop detects the closed device */
589
	/* make sure our event loop detects the closed device */
584
	dummy = 0;
590
	libusb10_wakeup_event_loop(ctx);
585
	err = write(ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
586
	if (err < (int)sizeof(dummy)) {
587
		/* ignore error, if any */
588
		DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_close write failed!");
589
	}
590
}
591
}
591
592
592
libusb_device *
593
libusb_device *
Lines 1314-1320 Link Here
1314
	int buffsize;
1315
	int buffsize;
1315
	int maxframe;
1316
	int maxframe;
1316
	int temp;
1317
	int temp;
1317
	uint8_t dummy;
1318
1318
1319
	dev = libusb_get_device(pdev);
1319
	dev = libusb_get_device(pdev);
1320
1320
Lines 1415-1424 Link Here
1415
1415
1416
failure:
1416
failure:
1417
	libusb10_complete_transfer(pxfer0, sxfer, LIBUSB_TRANSFER_ERROR);
1417
	libusb10_complete_transfer(pxfer0, sxfer, LIBUSB_TRANSFER_ERROR);
1418
1419
	/* make sure our event loop spins the done handler */
1418
	/* make sure our event loop spins the done handler */
1420
	dummy = 0;
1419
	libusb10_wakeup_event_loop(dev->ctx);
1421
	err = write(dev->ctx->ctrl_pipe[1], &dummy, sizeof(dummy));
1422
}
1420
}
1423
1421
1424
/* The following function must be called unlocked */
1422
/* The following function must be called unlocked */
Lines 1490-1495 Link Here
1490
	struct libusb20_transfer *pxfer1;
1488
	struct libusb20_transfer *pxfer1;
1491
	struct libusb_super_transfer *sxfer;
1489
	struct libusb_super_transfer *sxfer;
1492
	struct libusb_device *dev;
1490
	struct libusb_device *dev;
1491
	struct libusb_device_handle *devh;
1493
	uint8_t endpoint;
1492
	uint8_t endpoint;
1494
	int retval;
1493
	int retval;
1495
1494
Lines 1497-1508 Link Here
1497
		return (LIBUSB_ERROR_INVALID_PARAM);
1496
		return (LIBUSB_ERROR_INVALID_PARAM);
1498
1497
1499
	/* check if not initialised */
1498
	/* check if not initialised */
1500
	if (uxfer->dev_handle == NULL)
1499
	if ((devh = uxfer->dev_handle) == NULL)
1501
		return (LIBUSB_ERROR_NOT_FOUND);
1500
		return (LIBUSB_ERROR_NOT_FOUND);
1502
1501
1503
	endpoint = uxfer->endpoint;
1502
	endpoint = uxfer->endpoint;
1504
1503
1505
	dev = libusb_get_device(uxfer->dev_handle);
1504
	dev = libusb_get_device(devh);
1506
1505
1507
	DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer enter");
1506
	DPRINTF(dev->ctx, LIBUSB_DEBUG_FUNCTION, "libusb_cancel_transfer enter");
1508
1507
Lines 1513-1520 Link Here
1513
1512
1514
	CTX_LOCK(dev->ctx);
1513
	CTX_LOCK(dev->ctx);
1515
1514
1516
	pxfer0 = libusb10_get_transfer(uxfer->dev_handle, endpoint, 0);
1515
	pxfer0 = libusb10_get_transfer(devh, endpoint, 0);
1517
	pxfer1 = libusb10_get_transfer(uxfer->dev_handle, endpoint, 1);
1516
	pxfer1 = libusb10_get_transfer(devh, endpoint, 1);
1518
1517
1519
	if (sxfer->state != LIBUSB_SUPER_XFER_ST_PEND) {
1518
	if (sxfer->state != LIBUSB_SUPER_XFER_ST_PEND) {
1520
		/* only update the transfer status */
1519
		/* only update the transfer status */
Lines 1526-1531 Link Here
1526
		sxfer->entry.tqe_prev = NULL;
1525
		sxfer->entry.tqe_prev = NULL;
1527
		libusb10_complete_transfer(NULL,
1526
		libusb10_complete_transfer(NULL,
1528
		    sxfer, LIBUSB_TRANSFER_CANCELLED);
1527
		    sxfer, LIBUSB_TRANSFER_CANCELLED);
1528
		/* make sure our event loop spins the done handler */
1529
		libusb10_wakeup_event_loop(dev->ctx);
1529
	} else if (pxfer0 == NULL || pxfer1 == NULL) {
1530
	} else if (pxfer0 == NULL || pxfer1 == NULL) {
1530
		/* not started */
1531
		/* not started */
1531
		retval = LIBUSB_ERROR_NOT_FOUND;
1532
		retval = LIBUSB_ERROR_NOT_FOUND;
Lines 1532-1548 Link Here
1532
	} else if (libusb20_tr_get_priv_sc1(pxfer0) == sxfer) {
1533
	} else if (libusb20_tr_get_priv_sc1(pxfer0) == sxfer) {
1533
		libusb10_complete_transfer(pxfer0,
1534
		libusb10_complete_transfer(pxfer0,
1534
		    sxfer, LIBUSB_TRANSFER_CANCELLED);
1535
		    sxfer, LIBUSB_TRANSFER_CANCELLED);
1535
		libusb20_tr_stop(pxfer0);
1536
		if (libusb20_dev_check_connected(devh)) {
1536
		/* make sure the queue doesn't stall */
1537
			/* clear transfer pointer */
1537
		libusb10_submit_transfer_sub(
1538
			libusb20_tr_set_priv_sc1(pxfer0, NULL);
1538
		    uxfer->dev_handle, endpoint);
1539
			/* make sure our event loop spins the done handler */
1540
			libusb10_wakeup_event_loop(dev->ctx);
1541
		} else {
1542
			libusb20_tr_stop(pxfer0);
1543
			/* make sure the queue doesn't stall */
1544
			libusb10_submit_transfer_sub(devh, endpoint);
1545
		}
1539
	} else if (libusb20_tr_get_priv_sc1(pxfer1) == sxfer) {
1546
	} else if (libusb20_tr_get_priv_sc1(pxfer1) == sxfer) {
1540
		libusb10_complete_transfer(pxfer1,
1547
		libusb10_complete_transfer(pxfer1,
1541
		    sxfer, LIBUSB_TRANSFER_CANCELLED);
1548
		    sxfer, LIBUSB_TRANSFER_CANCELLED);
1542
		libusb20_tr_stop(pxfer1);
1549
		/* check if handle is still active */
1543
		/* make sure the queue doesn't stall */
1550
		if (libusb20_dev_check_connected(devh)) {
1544
		libusb10_submit_transfer_sub(
1551
			/* clear transfer pointer */
1545
		    uxfer->dev_handle, endpoint);
1552
			libusb20_tr_set_priv_sc1(pxfer1, NULL);
1553
			/* make sure our event loop spins the done handler */
1554
			libusb10_wakeup_event_loop(dev->ctx);
1555
		} else {
1556
			libusb20_tr_stop(pxfer1);
1557
			/* make sure the queue doesn't stall */
1558
			libusb10_submit_transfer_sub(devh, endpoint);
1559
		}
1546
	} else {
1560
	} else {
1547
		/* not started */
1561
		/* not started */
1548
		retval = LIBUSB_ERROR_NOT_FOUND;
1562
		retval = LIBUSB_ERROR_NOT_FOUND;
(-)lib/libusb/libusb10_io.c (-13 / +7 lines)
Lines 161-177 Link Here
161
		if (ppdev[i] != NULL) {
161
		if (ppdev[i] != NULL) {
162
			dev = libusb_get_device(ppdev[i]);
162
			dev = libusb_get_device(ppdev[i]);
163
163
164
			if (fds[i].revents == 0)
164
			if (fds[i].revents != 0) {
165
				err = 0;	/* nothing to do */
166
			else
167
				err = libusb20_dev_process(ppdev[i]);
165
				err = libusb20_dev_process(ppdev[i]);
168
166
169
			if (err) {
167
				if (err) {
170
				/* cancel all transfers - device is gone */
168
					/* remove USB device from polling loop */
171
				libusb10_cancel_all_transfer(dev);
169
					libusb10_remove_pollfd(dev->ctx, &dev->dev_poll);
172
170
				}
173
				/* remove USB device from polling loop */
174
				libusb10_remove_pollfd(dev->ctx, &dev->dev_poll);
175
			}
171
			}
176
			CTX_UNLOCK(ctx);
172
			CTX_UNLOCK(ctx);
177
			libusb_unref_device(dev);
173
			libusb_unref_device(dev);
Lines 180-189 Link Here
180
		} else {
176
		} else {
181
			uint8_t dummy;
177
			uint8_t dummy;
182
178
183
			while (1) {
179
			while (read(fds[i].fd, &dummy, 1) == 1)
184
				if (read(fds[i].fd, &dummy, 1) != 1)
180
				;
185
					break;
186
			}
187
		}
181
		}
188
	}
182
	}
189
183

Return to bug 231076