- /* Start background operation for subsequent events. */
- if (WaitCommEvent(port->hdl, &port->events, &port->wait_ovl) == 0) {
- if (GetLastError() != ERROR_IO_PENDING)
- RETURN_FAIL("WaitCommEvent() failed");
+ /* Restart wait operation if needed. */
+ if (GetOverlappedResult(port->hdl, &port->wait_ovl, &wait_result, FALSE)) {
+ /* Previous wait completed, start a new one. */
+ if (WaitCommEvent(port->hdl, &port->events, &port->wait_ovl) == 0) {
+ if (GetLastError() != ERROR_IO_PENDING)
+ RETURN_FAIL("WaitCommEvent() failed");
+ }
+ } else if (GetLastError() != ERROR_IO_INCOMPLETE) {
+ RETURN_FAIL("GetOverlappedResult() failed");