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

windows: Break out helper function for awaiting previous write completion.

This commit is contained in:
Martin Ling 2017-07-03 20:55:13 +01:00 committed by Uwe Hermann
parent 15541ebd78
commit 62ed9f801a

View File

@ -731,6 +731,27 @@ SP_API enum sp_return sp_drain(struct sp_port *port)
#endif
}
#ifdef _WIN32
static enum sp_return await_write_completion(struct sp_port *port)
{
TRACE("%p", port);
DWORD bytes_written;
BOOL result;
/* Wait for previous non-blocking write to complete, if any. */
if (port->writing) {
DEBUG("Waiting for previous write to complete");
result = GetOverlappedResult(port->hdl, &port->write_ovl, &bytes_written, TRUE);
port->writing = 0;
if (!result)
RETURN_FAIL("Previous write failed to complete");
DEBUG("Previous write completed");
}
RETURN_OK();
}
#endif
SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
size_t count, unsigned int timeout_ms)
{
@ -753,17 +774,8 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
#ifdef _WIN32
DWORD bytes_written = 0;
BOOL result;
/* Wait for previous non-blocking write to complete, if any. */
if (port->writing) {
DEBUG("Waiting for previous write to complete");
result = GetOverlappedResult(port->hdl, &port->write_ovl, &bytes_written, TRUE);
port->writing = 0;
if (!result)
RETURN_FAIL("Previous write failed to complete");
DEBUG("Previous write completed");
}
TRY(await_write_completion(port));
/* Set timeout. */
if (port->timeouts.WriteTotalTimeoutConstant != timeout_ms) {