CppLinuxSerial icon indicating copy to clipboard operation
CppLinuxSerial copied to clipboard

Flush write buffer

Open SanderEveraers opened this issue 3 years ago • 1 comments

Hi, First of all, thank you for providing this library, it has really helped during my current project. At this point if my application uses Ser.Write("my string"), it will stay in the write buffer until it is read by the connected device.

If for some reason, it isn't read, the buffer will keep older messages, resulting in unexpected messages when it is read at a later point, or even resulting in a segmentation fault when a buffer overflow occurs.

How can I flush the write buffer before calling Ser.Write("my string")?

SanderEveraers avatar Jan 05 '22 11:01 SanderEveraers

Hi @SanderEveraers , I did some quick Googling and think that tcflush() and tcdrain() might help? (see https://linux.die.net/man/3/tcdrain). tcflush seems to drop any data that is ready to be transmitted but not sent, whilst tcdrain() doesn't return until all pending data to be sent has been sent.

gbmhunter avatar Apr 30 '22 01:04 gbmhunter