From 8c9c6c8748ed2d164a002376c0a1711d75056af4 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Wed, 6 Nov 2024 16:34:06 -0800 Subject: [PATCH 1/2] Fix copy/paste error (errno == EAGAIN) was checked twice, where it should have been checking for EAGAIN or EWOULDBLOCK. --- src/usb_gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/usb_gadget.c b/src/usb_gadget.c index 46af429..6f7e5a7 100644 --- a/src/usb_gadget.c +++ b/src/usb_gadget.c @@ -113,7 +113,7 @@ int write_usb(usb_gadget * ctx, int channel, unsigned char * buffer, int size) { ret = write (ctx->ep_handles[channel], buffer, size); } - }while( ret < 0 && ( (errno == EAGAIN) || (errno == EAGAIN) ) && !mtp_context->cancel_req ); + }while( ret < 0 && ( (errno == EAGAIN) || (errno == EWOULDBLOCK) ) && !mtp_context->cancel_req ); fcntl(ctx->ep_handles[channel], F_SETFL, fcntl(ctx->ep_handles[channel], F_GETFL) & ~O_NONBLOCK); #else From 1e6936a432442a0fddb1ecfa178dd6e97d322434 Mon Sep 17 00:00:00 2001 From: Marco Nelissen Date: Wed, 6 Nov 2024 17:00:47 -0800 Subject: [PATCH 2/2] Fix video playback on Windows 10 Doing a blocking read (even with count=0) when handling a cancel request from the host ends up blocking both the read in the request handler as well as a write in the thread that's being cancelled, blocking both threads indefinitely. Removing the read appears to fix the problem. Fixes #108 --- src/usb_gadget.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/usb_gadget.c b/src/usb_gadget.c index 6f7e5a7..87a446d 100644 --- a/src/usb_gadget.c +++ b/src/usb_gadget.c @@ -498,8 +498,6 @@ static void handle_setup_request(usb_gadget * ctx, struct usb_ctrlrequest* setup case MTP_REQ_CANCEL: PRINT_DEBUG("MTP_REQ_CANCEL !"); - status = read (ctx->usb_device, &status, 0); - mtp_context->cancel_req = 1; cnt = 0;