On 13/02/13 13:02, Ramon Zambelli wrote:
I'm experiencing some unexpected behavior using the function
libusb_bulk_transfer on IN transaction. The version used is
1.0.14.10577 running on windows 7 x64.
Sometimes when the functions returns with timeout I can see some data
written in the buffer correctly but the transferred variable reports 0
bytes. On the next libusb_bulk_transfer call the data is not available
anymore and therefore it get lost.
Looking at the API documentation I read:
"Also check|transferred|when dealing with a timeout error code.
libusbx may have to split your transfer into a number of chunks to
satisfy underlying O/S requirements, meaning that the timeout may
expire after the first few chunks have completed. libusbx is careful
not to lose any data that may have been transferred; do not assume
that timeout conditions indicate a complete lack of I/O."
Checking with an HW sniffer I see the packet sent from the devices
correctly.
The problem happens more often if the timeout is set to few ms (in my
case I set 1ms to increase the error rate).
Is this a knows bug?
I've experienced something similar and it's been on my TODO list for
many months to have a look at it. Can you try the attached patch? This
helps in my situation where I see this issue, although I'm still seeing
some data loss which I've not had time to look into in more detail.
Regards,
Toby
>From 1ca6732246d1e7bbb54bc52f2560a0abaf5bb983 Mon Sep 17 00:00:00 2001
From: Toby Gray <toby.g...@realvnc.com>
Date: Wed, 13 Feb 2013 15:21:52 +0000
Subject: [PATCH] Windows: Update transferred data on timeout or cancel.
When handling aborted transfer it's possible that some data (but not
the full buffer) was transferred. This change ensures that this
partially transferred data is recorded and passed up to the caller.
# Please enter the commit message
for your changes. Lines starting # with '#' will be ignored, and an
empty message aborts the commit. # On branch master # Your branch is
ahead of 'origin/master' by 27 commits. # # Changes to be committed:
libusb/os/windows_usb.c # # Untracked files: # (use "git add
<file>..." to include in what will be committed) # # .emacs.desktop #
emacs-X11.exe.stackdump
---
libusb/os/windows_usb.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index 8a8caf4..fff21f3 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -2030,9 +2030,9 @@ static void windows_transfer_callback(struct usbi_transfer *itransfer, uint32_t
{
struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
- int status;
+ int status, istatus;
- usbi_dbg("handling I/O completion with errcode %d", io_result);
+ usbi_dbg("handling I/O completion with errcode %d, size %d", io_result, io_size);
switch(io_result) {
case NO_ERROR:
@@ -2047,6 +2047,10 @@ static void windows_transfer_callback(struct usbi_transfer *itransfer, uint32_t
status = LIBUSB_TRANSFER_TIMED_OUT;
break;
case ERROR_OPERATION_ABORTED:
+ istatus = priv->apib->copy_transfer_data(SUB_API_NOTSET, itransfer, io_size);
+ if (istatus != LIBUSB_TRANSFER_COMPLETED) {
+ usbi_dbg("Failed to copy partial data in aborted operation: %d", istatus);
+ }
if (itransfer->flags & USBI_TRANSFER_TIMED_OUT) {
usbi_dbg("detected timeout");
status = LIBUSB_TRANSFER_TIMED_OUT;
--
1.7.9
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel