wjwwood / serial

Cross-platform, Serial Port library written in C++
http://wjwwood.github.com/serial/
MIT License
2.13k stars 1.04k forks source link

Functions of flush, flushInput, and flushOutput #148

Open Qrox opened 7 years ago

Qrox commented 7 years ago

I have recently cloned the project and I'm a bit confused by the documentation for flush, flushInput, and flushOutput when trying to implement the latter two for Windows.

Currently the comment for flush says it flushes the input and output buffers, while the comments for flushInput and flushOutput say that they flush only the input/output buffers. The Unix implementation of the three functions, however, uses tcdrain and tcflush, and according to this page, tcdrain() waits until all output written to the object referred to by fd has been transmitted., which I believe means that the data in the output buffer will be sent through the port before they get cleared, while the input buffer will be kept intact; tcflush() discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of queue_selector, which I believe means that the data in the input buffer will be cleared, and the data in the output buffer will be cleared without being sent through the port.

Anyway, if flush means sending the data and then clearing the buffer, "flushing" an input buffer makes no sense to me (It's already sent to me, right?). So the best interpretation I can make is that flush flushes the output buffer, while flushInput and flushOutput clear the input/output buffers.

By the way, flushInput and flushOutput are currently unimplemented on windows. If they are meant to clear the buffer without sending their contents, PurgeComm will do the job.

Marviel commented 7 years ago

I'm also having trouble with flush. Bump