From: Uwe Hermann Date: Fri, 22 Jan 2016 14:30:44 +0000 (+0100) Subject: Fix sp_blocking_read_next() implementation on Windows. X-Git-Tag: libserialport-0.1.1~4 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=888fb45d66aada134f36fa9129499ec180161c0a;p=libserialport.git 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. --- 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)