From 5dd230d1fa6488abf9b15c59a9eaf114d32a1c47 Mon Sep 17 00:00:00 2001 From: HiFiPhile Date: Sat, 5 Apr 2025 12:49:32 +0200 Subject: [PATCH] win32: Abort WaitCommEvent() in sp_close() Fix an issue with Cypress CY7C652XX driver where overlapped IO is not released once the port handle is closed, cause following port open resulted in "Access denied" error. Not reproducible with FTDI or SiLabs drivers. Signed-off-by: HiFiPhile --- serialport.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/serialport.c b/serialport.c index b3b9249..ea1c707 100644 --- a/serialport.c +++ b/serialport.c @@ -689,6 +689,11 @@ SP_API enum sp_return sp_close(struct sp_port *port) DEBUG_FMT("Closing port %s", port->name); #ifdef _WIN32 + /* Abort WaitCommEvent() */ + if (SetCommMask(port->hdl, 0) == 0) { + RETURN_FAIL("SetCommMask() failed"); + } + /* Returns non-zero upon success, 0 upon failure. */ if (CloseHandle(port->hdl) == 0) RETURN_FAIL("Port CloseHandle() failed");