From cad5cb55c37137e94e35c74fdabfe42a5cbd229b Mon Sep 17 00:00:00 2001 From: David Moore Date: Wed, 27 May 2009 23:15:54 -0700 Subject: Make synchronous transfer APIs robust against signal interruption libusb_control_transfer and libusb_bulk_transfer are designed to be synchronous such that control is not returned until the transfer definitively succeeds or fails. That assumption is violated if a signal interrupts these functions because there is no way for the application to continue waiting for the transfer without resubmitting it. This patch changes these synchronous APIs so they do not abort in the case of a signal interruption. Signed-off-by: David Moore --- libusb/sync.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libusb/sync.c b/libusb/sync.c index 92e7833..72cbcf2 100644 --- a/libusb/sync.c +++ b/libusb/sync.c @@ -104,6 +104,8 @@ API_EXPORTED int libusb_control_transfer(libusb_device_handle *dev_handle, while (!completed) { r = libusb_handle_events(HANDLE_CTX(dev_handle)); if (r < 0) { + if (r == LIBUSB_ERROR_INTERRUPTED) + continue; libusb_cancel_transfer(transfer); while (!completed) if (libusb_handle_events(HANDLE_CTX(dev_handle)) < 0) @@ -172,6 +174,8 @@ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle, while (!completed) { r = libusb_handle_events(HANDLE_CTX(dev_handle)); if (r < 0) { + if (r == LIBUSB_ERROR_INTERRUPTED) + continue; libusb_cancel_transfer(transfer); while (!completed) if (libusb_handle_events(HANDLE_CTX(dev_handle)) < 0) -- cgit v1.2.1