]> sigrok.org Git - libserialport.git/commitdiff
Windows nonblocking write: Dont't return if async I/O finishes immediately.
authorMartin Ling <redacted>
Sat, 7 Dec 2013 20:16:38 +0000 (20:16 +0000)
committerMartin Ling <redacted>
Sat, 7 Dec 2013 20:16:38 +0000 (20:16 +0000)
serialport.c

index b7dd66a3bfad1220d319a75fb141cae588ee47e7..712b951daad2b765e3b661a6b506bbedd0aec54a 100644 (file)
@@ -1000,9 +1000,16 @@ enum sp_return sp_nonblocking_write(struct sp_port *port, const void *buf, size_
                /* Start asynchronous write. */
                if (WriteFile(port->hdl, &port->pending_byte, 1, NULL, &port->write_ovl) == 0) {
                        if (GetLastError() == ERROR_IO_PENDING) {
-                               DEBUG("Asynchronous write started");
-                               port->writing = 1;
-                               RETURN_VALUE("%d", ++written);
+                               if (HasOverlappedIoCompleted(&port->write_ovl)) {
+                                       DEBUG("Asynchronous write completed immediately");
+                                       port->writing = 0;
+                                       written++;
+                                       continue;
+                               } else {
+                                       DEBUG("Asynchronous write running");
+                                       port->writing = 1;
+                                       RETURN_VALUE("%d", ++written);
+                               }
                        } else {
                                /* Actual failure of some kind. */
                                RETURN_FAIL("WriteFile() failed");