From ae2c5825e79ab5b38a8ca53941df6d73679a52e6 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 8 Dec 2015 20:08:49 +0000 Subject: [PATCH] windows: Handle ERROR_IO_PENDING from ReadFile in sp_nonblocking_read(). This fixes bug #707. --- serialport.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/serialport.c b/serialport.c index 2f7618e..520d27e 100644 --- a/serialport.c +++ b/serialport.c @@ -1234,10 +1234,11 @@ SP_API enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf, /* Do read. */ if (ReadFile(port->hdl, buf, count, NULL, &port->read_ovl) == 0) - RETURN_FAIL("ReadFile() failed"); + if (GetLastError() != ERROR_IO_PENDING) + RETURN_FAIL("ReadFile() failed"); /* Get number of bytes read. */ - if (GetOverlappedResult(port->hdl, &port->read_ovl, &bytes_read, TRUE) == 0) + if (GetOverlappedResult(port->hdl, &port->read_ovl, &bytes_read, FALSE) == 0) RETURN_FAIL("GetOverlappedResult() failed"); TRY(restart_wait_if_needed(port, bytes_read));