add support for drain

Tested on Mac OS, Linux and Windows with UART emulated on USB.

I wrote general BSD code, because it should work, but I am not able to test
it.

On Mac OS I am quite sure that drain behaves as expected because it fixed
an issue with buffer overflow (which OS does not report but fails).

For Windows it seems that drain is actually part of `Write`, because
`Write` was long and `Drain` was fast. But I have not found any mention in
Win32 docs about buffering and asynchronous write, so I put there flushing
code to be sure, and this code did not break anything.

For Linux `Drain` is also taking more time than writing so it looks working
too.
This commit is contained in:
Tomáš Polomský
2020-05-09 08:34:28 +02:00
parent e381f2c133
commit ff38fe2a78
4 changed files with 27 additions and 0 deletions

View File

@@ -119,6 +119,10 @@ func (port *windowsPort) Write(p []byte) (int, error) {
return int(writed), err
}
func (port *windowsPort) Drain() (err error) {
return syscall.FlushFileBuffers(port.handle)
}
const (
purgeRxAbort uint32 = 0x0002
purgeRxClear = 0x0008