Unix: fix Mark/Space parity emulation
The QSerialPortPrivate::writePerChar() method was introduced back in
28fe4bf781ac20cb4fcb39de81b9d76cd100ea5d to emulate Mark/Space parity
on UNIX systems that do not support CMSPAR. The original logic was to
toggle the odd/even parity after each character. In order to make it
work, the output buffer was flushed after each character. Originally,
a blocking UNIX call ::tcdrain() was used for that (wrapped into a
nativeFlush() helper function for error handling).
During the module evolution, the original call to nativeFlush() was
replaced with QSerialPortPrivate::flush(), which was later made
non-blocking in d402b2cd84fc55c6c9399bb4fc9e1ad764c07cde. That commit
seemed to introduce an infinite recursion into writePerChar().
The loop is as follows:
writePerChar() -> flush() -> completeAsyncWrite() -> startAsyncWrite()
-> writeToPort() -> writePerChar() again.
Fix it by reintroducing the native ::tcdrain() call together with
the error handling. Provide an explicit unit-test that sets the
Mark/Space parity and performs communication.
The parch was tested on macOS (which does not define CMSPAR) with two
FTDI FT232 serial converters. The tests revealed that the reading
part is missing the Mark/Space parify emulation. A separate task was
created to handle this bug.
Fixes: QTBUG-105561
Task-number: QTBUG-131679
Pick-to: 6.9 6.8 6.5 5.15
Change-Id: I137c09c905f98ec59f883dbf22b17df75edb03c4
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>