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

Add sp_drain() function.

This commit is contained in:
Martin Ling 2013-11-20 17:30:50 +00:00 committed by Bert Vermeulen
parent ea34fba899
commit 69a3739ca0
2 changed files with 25 additions and 0 deletions

View File

@ -526,6 +526,14 @@ enum sp_return sp_write(struct sp_port *port, const void *buf, size_t count);
*/
enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers);
/**
* Wait for buffered data to be transmitted.
*
* @return SP_OK on success, SP_ERR_FAIL on failure, or SP_ERR_ARG
* if an invalid port is passed.
*/
enum sp_return sp_drain(struct sp_port *port);
/**
* @}
* @defgroup Errors Obtaining error information

View File

@ -535,6 +535,23 @@ enum sp_return sp_flush(struct sp_port *port, enum sp_buffer buffers)
return SP_OK;
}
enum sp_return sp_drain(struct sp_port *port)
{
CHECK_PORT();
#ifdef _WIN32
/* Returns non-zero upon success, 0 upon failure. */
if (FlushFileBuffers(port->hdl) == 0)
return SP_ERR_FAIL;
#else
/* Returns 0 upon success, -1 upon failure. */
if (tcdrain(port->fd) < 0)
return SP_ERR_FAIL;
#endif
return SP_OK;
}
enum sp_return sp_write(struct sp_port *port, const void *buf, size_t count)
{
CHECK_PORT();