From 888fb45d66aada134f36fa9129499ec180161c0a Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Fri, 22 Jan 2016 15:30:44 +0100 Subject: [PATCH] Fix sp_blocking_read_next() implementation on Windows. A ReadFile() call needed to check the actual number of bytes read, instead of assuming all requested bytes were read. --- serialport.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/serialport.c b/serialport.c index c4a0e1b..fb603b3 100644 --- a/serialport.c +++ b/serialport.c @@ -1112,9 +1112,8 @@ SP_API enum sp_return sp_blocking_read_next(struct sp_port *port, void *buf, /* Loop until we have at least one byte, or timeout is reached. */ while (bytes_read == 0) { /* Start read. */ - if (ReadFile(port->hdl, buf, count, NULL, &port->read_ovl)) { + if (ReadFile(port->hdl, buf, count, &bytes_read, &port->read_ovl)) { DEBUG("Read completed immediately"); - bytes_read = count; } else if (GetLastError() == ERROR_IO_PENDING) { DEBUG("Waiting for read to complete"); if (GetOverlappedResult(port->hdl, &port->read_ovl, &bytes_read, TRUE) == 0)