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:
parent
15541ebd78
commit
62ed9f801a
32
serialport.c
32
serialport.c
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user