From 52e817c85ebba7e39fb3a9f23b22dc26ed6b934a Mon Sep 17 00:00:00 2001 From: RD-AP-PPT <69512315+RD-AP-PPT@users.noreply.github.com> Date: Thu, 6 May 2021 17:35:24 +0200 Subject: [PATCH] ignore Interrupted system call error and retry (#1499) --- .../System/Device/Gpio/LibgpiodDriverEventHandler.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/System.Device.Gpio/System/Device/Gpio/LibgpiodDriverEventHandler.cs b/src/System.Device.Gpio/System/Device/Gpio/LibgpiodDriverEventHandler.cs index e9a4d42e..32d332e8 100644 --- a/src/System.Device.Gpio/System/Device/Gpio/LibgpiodDriverEventHandler.cs +++ b/src/System.Device.Gpio/System/Device/Gpio/LibgpiodDriverEventHandler.cs @@ -11,6 +11,8 @@ namespace System.Device.Gpio.Drivers { internal sealed class LibGpiodDriverEventHandler : IDisposable { + private const int ERROR_CODE_EINTR = 4; // Interrupted system call + private static string s_consumerName = Process.GetCurrentProcess().ProcessName; public event PinChangeEventHandler? ValueRising; @@ -55,7 +57,14 @@ namespace System.Device.Gpio.Drivers WaitEventResult waitResult = Interop.libgpiod.gpiod_line_event_wait(pinHandle, ref timeout); if (waitResult == WaitEventResult.Error) { - throw ExceptionHelper.GetIOException(ExceptionResource.EventWaitError, Marshal.GetLastWin32Error(), _pinNumber); + var errorCode = Marshal.GetLastWin32Error(); + if (errorCode == ERROR_CODE_EINTR) + { + // ignore Interrupted system call error and retry + continue; + } + + throw ExceptionHelper.GetIOException(ExceptionResource.EventWaitError, errorCode, _pinNumber); } if (waitResult == WaitEventResult.EventOccured) -- GitLab