Xiaofan Chen | 1 Nov 2010 04:20
Picon

Re: [libusb] #70: device removal breaks internal state, making later libusb_open calls always fail

Just an historical information here. I believe libusb-win32 is okay
as well.

But it might be interesting to re-write Stephan Meyer's test program
with libusb-1.0 under Windows and see how it works.

-- 
Xiaofan

On Fri, Sep 29, 2006 at 2:55 AM, Stephan Meyer wrote:
>
> I tried the same on my system (WinXP, 2GHz CPU) and my test program
> (code attached) consumes less than 5% of CPU resources.
>
> But if I enable debugging by calling usb_set_debug(4) and if I connect
> a tool such as DebugView to capture the debug messages then CPU
> load goes up to 80%.
>
> Try to disable debug messages by calling usb_set_debug(0) after usb_init().
>
> My test program also calls usb_find_devices() from a seperate thread and
> it doesn't crash (as you mentioned in your other mail). If I unplug my device
> then the application just terminates.
> The current DLL isn't fully thread safe but refreshing the device list from
> a second thread shouldn't crash the DLL.
>
> Which version of the DLL are you using? Have you tried one of the latest
> development versions?
>
> Stephan
(Continue reading)

Xiaofan Chen | 1 Nov 2010 04:29
Picon

libusb-1.0 simple multi-thread test program for Windows

I admit I know very little about multi-thread programming. And it seems to me
that I have not see a simple multi-thread test program for the Windows
backend (using native Win32 threading).

The following program (using native Win32 threading and libusb-win32)
is from Stephan Meyer (using libusb-win32). Maybe someone can convert
it to libusb-1.0 under Windows.

 #include <stdio.h>
 #include <windows.h>

 #include "usb.h"

 static int read_thread_running = 1;
 static int write_thread_running = 1;

 #define NUM_LOOPS 1000

 static DWORD WINAPI thread_proc_read(void *param);
 static DWORD WINAPI thread_proc_write(void *param);
 static struct usb_device *find_dev(void);

 static DWORD WINAPI thread_proc_read(void *param)
 {
   char tmp[1024];
   int i;
   usb_dev_handle *hdev = (usb_dev_handle *)param;

   printf("thread_proc_read: starts\n");

(Continue reading)

Xiaofan Chen | 1 Nov 2010 05:06
Picon

Re: [libusb] #70: device removal breaks internal state, making later libusb_open calls always fail

On Thu, Oct 28, 2010 at 4:07 AM, Peter Stuge <peter <at> stuge.se> wrote:
> Pete Batard wrote:
>> On 2010.10.27 15:46, libusb Trac wrote:
>> >   Since this is a backend problem I would very much appreciate if someone
>> >   could test for this problem also on MacOS X and Windows.
>>
>> Tested for Windows using the sample program attached to the trac issue.
>
> Thanks for testing!
>
>
>> Haven't observed crashes of libusb,
>
> Note that there is no crash as in access violation. The "crash"
> refers to internal state which makes libusb_open fail.
>

I just tested it under Linux and actually the program does not work
even without unplug/plug. Strange.

Without the sleep(1) code, even without unplug/plug the program
does not work.

Initially it works, after a while, the program failed like this.

try to open device...
libusb:error [sysfs_scan_device] open busnum failed, errno=24
could not open device

try to open device...
(Continue reading)

Xiaofan Chen | 1 Nov 2010 05:12
Picon

Re: libusb_get_device_list fails with "No such file of directory"

Rehash the thread as it is related to ticket #70.
http://www.libusb.org/ticket/70

On Wed, Jun 30, 2010 at 6:45 PM, Felipe Balbi
<felipebalbi <at> users.sourceforge.net> wrote:
> Hi,
>
> On Wed, Jun 23, 2010 at 9:13 AM, Felipe Balbi
> <felipebalbi <at> users.sourceforge.net> wrote:
>> so adding new devices to the bus works fine, it fails when a device is
>> removed. Will try disabling
>> sysfs from libusb and always using usbfs and see if it works.
>
> any news here ?? this seems like a bug on __open_sysfs_attr() which is
> easy to trigger
> with something that will only keep on getting device list, like:
>
> #include <stdio.h>
> #include <errno.h>
> #include <sys/types.h>
> #include <libusb-1.0/libusb.h>
>
> int main(int argc, char *argv[])
> {
>        libusb_device           **list;
>        libusb_context          *context;
>
>        int                     ret = 0;
>
>        ssize_t                 cnt;
(Continue reading)

Xiaofan Chen | 1 Nov 2010 05:20
Picon

Re: libusb_get_device_list fails with "No such file of directory"

On Mon, Nov 1, 2010 at 12:12 PM, Xiaofan Chen <xiaofanc <at> gmail.com> wrote:
> Rehash the thread as it is related to ticket #70.
> http://www.libusb.org/ticket/70
>
> On Wed, Jun 30, 2010 at 6:45 PM, Felipe Balbi
> <felipebalbi <at> users.sourceforge.net> wrote:
>> Hi,
>>
>> On Wed, Jun 23, 2010 at 9:13 AM, Felipe Balbi
>> <felipebalbi <at> users.sourceforge.net> wrote:
>>> so adding new devices to the bus works fine, it fails when a device is
>>> removed. Will try disabling
>>> sysfs from libusb and always using usbfs and see if it works.
>>
>> any news here ?? this seems like a bug on __open_sysfs_attr() which is
>> easy to trigger
>> with something that will only keep on getting device list, like:
>>
>> #include <stdio.h>
>> #include <errno.h>
>> #include <sys/types.h>
>> #include <libusb-1.0/libusb.h>
>>
>> int main(int argc, char *argv[])
>> {
>>        libusb_device           **list;
>>        libusb_context          *context;
>>
>>        int                     ret = 0;
>>
(Continue reading)

Xiaofan Chen | 1 Nov 2010 06:14
Picon

Re: libusb_get_device_list fails with "No such file of directory"

Then I tested the following similar program under Windows with
the latest binary snapshot (pbr317).

#include <sys/types.h>
#include <libusb-1.0/libusb.h>

int main(int argc, char *argv[])
{
       libusb_device           **list;

       int                     ret = 0;

       ssize_t                 cnt;

       libusb_init(NULL);
	   libusb_set_debug(NULL, 4);

       while (1) {
               cnt = libusb_get_device_list(NULL, &list);
               if (cnt < 0) {
                       ret = cnt;
                       perror("failed to get device list: ");
                       libusb_free_device_list(list, 1);
                       goto out;
               }

               libusb_free_device_list(list, 1);
               Sleep(1);
       }

(Continue reading)

Xiaofan Chen | 1 Nov 2010 06:36
Picon

Re: [libusb] #70: device removal breaks internal state, making later libusb_open calls always fail

On Mon, Nov 1, 2010 at 12:06 PM, Xiaofan Chen <xiaofanc <at> gmail.com> wrote:
> I just tested it under Linux and actually the program does not work
> even without unplug/plug. Strange.
>
> Without the sleep(1) code, even without unplug/plug the program
> does not work.

I think the program is not valid since it does not close the device
handle.

So I change the program to the following.

#include <libusb-1.0/libusb.h>
#include <stdio.h>
//#include <unistd.h>

// VID/PID anonymized ;-)
#define VENDOR_ID 0x0925
#define PRODUCT_ID 0x7001

// remove this define to avoid the error (appends sleep(1) to the loop)
//#define BREAK_LIBUSB

libusb_device_handle *m_device;

int main(void)
{
    if (libusb_init(NULL) != 0)
    {
        printf("could not init libusb context\n");
(Continue reading)

libusb Trac | 1 Nov 2010 06:38
Favicon

Re: [libusb] #70: device removal breaks internal state, making later libusb_open calls always fail

#70: device removal breaks internal state, making later libusb_open calls always
fail
-------------------------+--------------------------------------------------
  Reporter:  hagg        |        Owner:     
      Type:  defect      |       Status:  new
 Component:  libusb-1.0  |   Resolution:     
  Keywords:  linux       |       Blocks:     
Blocked By:              |  
-------------------------+--------------------------------------------------

Comment (by xiaofan):

 I am not that sure if the program is valid as it does not close the device
 handle before opening it again.

--

-- 
Ticket URL: <http://libusb.org/ticket/70#comment:3>
libusb <http://libusb.org/>
C library for writing portable USB drivers in userspace
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
libusb Trac | 1 Nov 2010 08:09
Favicon

Re: [libusb] #70: device removal breaks internal state, making later libusb_open calls always fail

#70: device removal breaks internal state, making later libusb_open calls always
fail
-------------------------+--------------------------------------------------
  Reporter:  hagg        |        Owner:     
      Type:  defect      |       Status:  new
 Component:  libusb-1.0  |   Resolution:     
  Keywords:  linux       |       Blocks:     
Blocked By:              |  
-------------------------+--------------------------------------------------

Comment (by hagg):

 Replying to [comment:3 xiaofan]:
 > I am not that sure if the program is valid as it does not close the
 device handle before opening it again.

 indeed there does not seem to be a difference if you close the device
 again after opening it successfully, and when opening fails and
 libusb_open_device_with_vid_pid(..) returns NULL there is no handle to
 close.

 using this code in the loop does not change anything for me:
 {{{
         m_device = libusb_open_device_with_vid_pid(NULL,
                                                    VENDOR_ID, PRODUCT_ID);
         if (m_device == NULL)
         {
             printf("could not open device\n");
         } else
         {
(Continue reading)

libusb Trac | 1 Nov 2010 09:09
Favicon

Re: [libusb] #70: device removal breaks internal state, making later libusb_open calls always fail

#70: device removal breaks internal state, making later libusb_open calls always
fail
-------------------------+--------------------------------------------------
  Reporter:  hagg        |        Owner:     
      Type:  defect      |       Status:  new
 Component:  libusb-1.0  |   Resolution:     
  Keywords:  linux       |       Blocks:     
Blocked By:              |  
-------------------------+--------------------------------------------------

Comment (by xiaofan):

 If you can, please subscribe to the mailing list. In the discussion, Pete
 already mentioned the problem with your test program.

 http://libusb.6.n5.nabble.com/libusb-70-not-possible-to-re-open-a-device-
 that-was-switched-off-while-opened-td3235177.html

 As for the result under Linux, at least it works at normal state. Without
 sleeep(1) line, when you unplug the device and plug it back in (for me, I
 press the reset button), sometimes it will not work (no long be able to
 open the device). Sometime it works (especially if I only press the button
 shortly). So indeed there is a problem with libusb in this situation under
 Linux. Please refer to the thread I mentioned before.
 http://libusb.6.n5.nabble.com/libusb-get-device-list-fails-with-No-such-
 file-of-directory-td510637.html

 With the sleep(1), the code works under Linux (tested with latest
 libusb.git and Ubuntu 10.10 32bit).

(Continue reading)


Gmane