]> sigrok.org Git - libserialport.git/commitdiff
Add handling of ERROR_OPERATION_ABORTED in restart_wait for WIN32
authorPatrick Dussud <redacted>
Mon, 17 Jun 2024 18:58:36 +0000 (11:58 -0700)
committerSoeren Apel <redacted>
Fri, 30 Aug 2024 20:17:22 +0000 (22:17 +0200)
It appears that the standard Win11 CDC driver does produce this case on occasion when the last byte of the IO has been transferred.

serialport.c

index 1b5a95e21d87fdfe48c7c10d686a47e2acac0e24..58b3c3e14777db0aac7245e5e81ca5f4f4c96e45 100644 (file)
@@ -420,7 +420,7 @@ SP_API void sp_free_port_list(struct sp_port **list)
 /** To be called after port receive buffer is emptied. */
 static enum sp_return restart_wait(struct sp_port *port)
 {
-       DWORD wait_result;
+       DWORD wait_result, last_error_code;
 
        if (port->wait_running) {
                /* Check status of running wait operation. */
@@ -428,7 +428,10 @@ static enum sp_return restart_wait(struct sp_port *port)
                                &wait_result, FALSE)) {
                        DEBUG("Previous wait completed");
                        port->wait_running = FALSE;
-               } else if (GetLastError() == ERROR_IO_INCOMPLETE) {
+               } else if ((last_error_code = GetLastError()) == ERROR_OPERATION_ABORTED) {
+                       DEBUG("Previous wait aborted");
+                       port->wait_running = FALSE;
+               } else if (last_error_code == ERROR_IO_INCOMPLETE) {
                        DEBUG("Previous wait still running");
                        RETURN_OK();
                } else {