1 (edited by timothyp 2019-03-18 21:16:21)

Topic: DeviceList.Local.Changed not triggered on Linux without modifications

Without modification `DeviceList.Local.Changed` does not get triggered on Ubuntu 18.04

Filename: `LinuxHidManager.cs`
Line: ~69

This is the code in the current version

if (0 != (fds[0].revents & (NativeMethods.pollev.ERR | NativeMethods.pollev.HUP | NativeMethods.pollev.NVAL))) { break; }                       
if (0 != (fds[0].revents & NativeMethods.pollev.IN))
{                                
    IntPtr device = NativeMethodsLibudev.Instance.udev_monitor_receive_device(monitor);
    if (device != null)
    {                                    
        NativeMethodsLibudev.Instance.udev_device_unref(device);
        DeviceList.Local.RaiseChanged();
    }
}

The following line never returns true:

if (0 != (fds[0].revents & NativeMethods.pollev.IN))

However, if I disable this check I get proper change notification and no exceptions.
Basically, the following version works:

if (ret == 1)
{

    if (0 != (fds[0].revents & (NativeMethods.pollev.ERR | NativeMethods.pollev.HUP | NativeMethods.pollev.NVAL))) { break; }                       

                                   
   IntPtr device = NativeMethodsLibudev.Instance.udev_monitor_receive_device(monitor);
    if (device != null)
    {                                    
        NativeMethodsLibudev.Instance.udev_device_unref(device);
        DeviceList.Local.RaiseChanged();
    }
   
}

Do you see any issue with this?

PS: Again, it would be really great if you had an official git repo for this, it is such a useful project.

2

Re: DeviceList.Local.Changed not triggered on Linux without modifications

Very odd. What is revents returning for you, then?
Also, is it blocking in poll in your version, or blocking in udev_monitor_receive_device? Thanks!

3

Re: DeviceList.Local.Changed not triggered on Linux without modifications

Sorry to get back to this so late.
Was using my version so forgot about the issue.
Now I switched back to your latest version (since you solved some other issues)
and found that this issue still exists.

4

Re: DeviceList.Local.Changed not triggered on Linux without modifications

So in my case revents always equals 0 in this check:

`if (0 != (fds[0].revents & NativeMethods.pollev.IN))`

And if I remove this check, all is fine.

Also note that once a device is connected this code is executed in an endless loop,

5

Re: DeviceList.Local.Changed not triggered on Linux without modifications

Hmm. I am not encountering this problem on Linux Mint 19. (Are you running 32 or 64-bit? Which architecture?)

"if (0 != (fds[0].revents & NativeMethods.pollev.IN))" runs in an endless loop? What is the value of fds[0].revents? Thanks!

6

Re: DeviceList.Local.Changed not triggered on Linux without modifications

`fds[0].revents` is always 0

So far I have only tested on x64, can try on ARM later.

7

Re: DeviceList.Local.Changed not triggered on Linux without modifications

Just on the possibility that this is Platform Invoke related, would you mind trying:

In Platform\Linux\NativeMethods.cs

change

public static extern int poll(pollfd[] fds, IntPtr nfds, int timeout);

to

public static extern int poll([In][Out] pollfd[] fds, IntPtr nfds, int timeout);

8

Re: DeviceList.Local.Changed not triggered on Linux without modifications

Try this:
https://www.zer7.com/files/oss/hidsharp … -07-20.zip