#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)
{
#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) {