1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00

windows: Fix restart of RX/error wait operation after reads.

This fixes bug #421.
This commit is contained in:
Martin Ling 2014-09-24 15:30:39 +01:00 committed by Uwe Hermann
parent e31f2c6b8b
commit f446cfbf65

View File

@ -888,6 +888,7 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
#ifdef _WIN32 #ifdef _WIN32
DWORD bytes_read = 0; DWORD bytes_read = 0;
DWORD wait_result = 0;
/* Set timeout. */ /* Set timeout. */
port->timeouts.ReadIntervalTimeout = 0; port->timeouts.ReadIntervalTimeout = 0;
@ -909,10 +910,15 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
bytes_read = count; bytes_read = count;
} }
/* Start background operation for subsequent events. */ /* Restart wait operation if needed. */
if (WaitCommEvent(port->hdl, &port->events, &port->wait_ovl) == 0) { if (GetOverlappedResult(port->hdl, &port->wait_ovl, &wait_result, FALSE)) {
if (GetLastError() != ERROR_IO_PENDING) /* Previous wait completed, start a new one. */
RETURN_FAIL("WaitCommEvent() failed"); 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");
} }
RETURN_INT(bytes_read); RETURN_INT(bytes_read);
@ -994,6 +1000,7 @@ SP_API enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf,
#ifdef _WIN32 #ifdef _WIN32
DWORD bytes_read; DWORD bytes_read;
DWORD wait_result;
/* Set timeout. */ /* Set timeout. */
port->timeouts.ReadIntervalTimeout = MAXDWORD; port->timeouts.ReadIntervalTimeout = MAXDWORD;
@ -1009,12 +1016,15 @@ SP_API enum sp_return sp_nonblocking_read(struct sp_port *port, void *buf,
if (GetOverlappedResult(port->hdl, &port->read_ovl, &bytes_read, TRUE) == 0) if (GetOverlappedResult(port->hdl, &port->read_ovl, &bytes_read, TRUE) == 0)
RETURN_FAIL("GetOverlappedResult() failed"); RETURN_FAIL("GetOverlappedResult() failed");
if (bytes_read > 0) { /* Restart wait operation if needed. */
/* Start background operation for subsequent events. */ 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 (WaitCommEvent(port->hdl, &port->events, &port->wait_ovl) == 0) {
if (GetLastError() != ERROR_IO_PENDING) if (GetLastError() != ERROR_IO_PENDING)
RETURN_FAIL("WaitCommEvent() failed"); RETURN_FAIL("WaitCommEvent() failed");
} }
} else if (GetLastError() != ERROR_IO_INCOMPLETE) {
RETURN_FAIL("GetOverlappedResult() failed");
} }
RETURN_INT(bytes_read); RETURN_INT(bytes_read);