]> sigrok.org Git - libserialport.git/commitdiff
Fix sp_blocking_read_next() implementation on Windows.
authorUwe Hermann <redacted>
Fri, 22 Jan 2016 14:30:44 +0000 (15:30 +0100)
committerUwe Hermann <redacted>
Fri, 22 Jan 2016 14:32:00 +0000 (15:32 +0100)
A ReadFile() call needed to check the actual number of bytes read,
instead of assuming all requested bytes were read.

serialport.c

index c4a0e1b96e5dbc50e6754fcc55c48fa8c26822e7..fb603b3edc97c0a5e317b80df7ca870633113792 100644 (file)
@@ -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)