Fix a race condition at writing on Windows


1. The writeStarted flag shall be reset to false after bytesWritten() signal
is emitted, but not before it.

2. In case of start of writing from the startAsyncWriteTimer it is necessary
to call the startAsyncWrite() method but not the completeAsyncWrite() method.

It give guarantees to exclude of race condition to multiple call of the
WriteFile twice until the write operation is not completed.

For example, a race condition is watched in case of writing data from the
slots which are connected to the bytesWritten() signal from a device; or to
the timeout() signal from a timer with zero interval. To checking of these
scenarios are added additional autotests.

Tested on Windows 8 with the on-board and USB serial ports, using Qt5.

Task-number: QTBUG-40769
Change-Id: Iedabbf38847debeee795a10fd7a4c54c65d2a338
Reviewed-by: Patrick Noffke <patrick.noffke@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
commitb4d5bd813f591dc618e0fff2d55d93eeccb1a26e
parent286d64c202f461cb8ff5a4cc4c2320af8195b8f0
authorDenis Shienkov <denis.shienkov@gmail.com>
committerDenis Shienkov <denis.shienkov@gmail.com>
commit timeThu, 28 Aug 2014 21:17:50 +0200