Skip to content

Commit

Permalink
Merge pull request #34 from DaVarga/bugfix/#8/infinite-loop-in-LinuxH…
Browse files Browse the repository at this point in the history
…idManager.Run

Fix Infinite loop in LinuxHidManager.Run (#8)
  • Loading branch information
benedekkupper authored Sep 17, 2024
2 parents 45e6d55 + 5fa6e42 commit a0a1f6c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions HidSharp/Platform/Linux/LinuxHidManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ protected override void Run(Action readyCallback)
int fd = NativeMethodsLibudev.Instance.udev_monitor_get_fd(monitor);
RunAssert(fd >= 0, "HidSharp udev_monitor_get_fd failed.");

var fds = new NativeMethods.pollfd[1];
fds[0].fd = fd;
fds[0].events = NativeMethods.pollev.IN;
var pfd = new NativeMethods.pollfd();
pfd.fd = fd;
pfd.events = NativeMethods.pollev.IN;

readyCallback();
while (true)
{
ret = NativeMethods.retry(() => NativeMethods.poll(fds, (IntPtr)1, -1));
ret = NativeMethods.retry(() => NativeMethods.poll(ref pfd, (IntPtr)1, -1));
if (ret < 0) { break; }

if (ret == 1)
{
if (0 != (fds[0].revents & (NativeMethods.pollev.ERR | NativeMethods.pollev.HUP | NativeMethods.pollev.NVAL))) { break; }
if (0 != (fds[0].revents & NativeMethods.pollev.IN))
if (0 != (pfd.events & (NativeMethods.pollev.ERR | NativeMethods.pollev.HUP | NativeMethods.pollev.NVAL))) { break; }
if (0 != (pfd.events & NativeMethods.pollev.IN))
{
IntPtr device = NativeMethodsLibudev.Instance.udev_monitor_receive_device(monitor);
if (device != null)
Expand Down

0 comments on commit a0a1f6c

Please sign in to comment.