From de14b5cd04fd9fbbb1efa62a0a910644a403faa3 Mon Sep 17 00:00:00 2001 From: IP Susila Date: Wed, 23 Aug 2017 13:52:09 +0700 Subject: [PATCH] Fix issue #48 (errno 0), https://github.com/tarm/serial/issues/48 --- serial_linux.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/serial_linux.go b/serial_linux.go index adf18c6..afb3240 100644 --- a/serial_linux.go +++ b/serial_linux.go @@ -143,13 +143,17 @@ func (p *Port) Write(b []byte) (n int, err error) { // or data received but not read func (p *Port) Flush() error { const TCFLSH = 0x540B - _, _, err := syscall.Syscall( + _, _, errno := syscall.Syscall( syscall.SYS_IOCTL, uintptr(p.f.Fd()), uintptr(TCFLSH), uintptr(syscall.TCIOFLUSH), ) - return err + + if errno == 0 { + return nil + } + return errno } func (p *Port) Close() (err error) {