Skip to content

Commit 5fa6e42

Browse files
committed
Fix Infinite loop in LinuxHidManager.Run (#8)
1 parent 45e6d55 commit 5fa6e42

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

HidSharp/Platform/Linux/LinuxHidManager.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ protected override void Run(Action readyCallback)
5353
int fd = NativeMethodsLibudev.Instance.udev_monitor_get_fd(monitor);
5454
RunAssert(fd >= 0, "HidSharp udev_monitor_get_fd failed.");
5555

56-
var fds = new NativeMethods.pollfd[1];
57-
fds[0].fd = fd;
58-
fds[0].events = NativeMethods.pollev.IN;
56+
var pfd = new NativeMethods.pollfd();
57+
pfd.fd = fd;
58+
pfd.events = NativeMethods.pollev.IN;
5959

6060
readyCallback();
6161
while (true)
6262
{
63-
ret = NativeMethods.retry(() => NativeMethods.poll(fds, (IntPtr)1, -1));
63+
ret = NativeMethods.retry(() => NativeMethods.poll(ref pfd, (IntPtr)1, -1));
6464
if (ret < 0) { break; }
6565

6666
if (ret == 1)
6767
{
68-
if (0 != (fds[0].revents & (NativeMethods.pollev.ERR | NativeMethods.pollev.HUP | NativeMethods.pollev.NVAL))) { break; }
69-
if (0 != (fds[0].revents & NativeMethods.pollev.IN))
68+
if (0 != (pfd.events & (NativeMethods.pollev.ERR | NativeMethods.pollev.HUP | NativeMethods.pollev.NVAL))) { break; }
69+
if (0 != (pfd.events & NativeMethods.pollev.IN))
7070
{
7171
IntPtr device = NativeMethodsLibudev.Instance.udev_monitor_receive_device(monitor);
7272
if (device != null)

0 commit comments

Comments
 (0)