From 1131ba52fdadb0d07a0fe7332e3b58aa85bfaa61 Mon Sep 17 00:00:00 2001 From: Andrey Demenev Date: Sun, 3 Feb 2019 03:35:32 +1000 Subject: [PATCH] Do not return -1 from Read() and Write() Closes #55 --- serial_unix.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/serial_unix.go b/serial_unix.go index 8831fc2..c796c30 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -74,12 +74,19 @@ func (port *unixPort) Read(p []byte) (int, error) { if err == unix.EINTR { continue } + if n < 0 { // Do not return -1 unix errors + n = 0 + } return n, err } } func (port *unixPort) Write(p []byte) (n int, err error) { - return unix.Write(port.handle, p) + n, err = unix.Write(port.handle, p) + if n < 0 { // Do not return -1 unix errors + n = 0 + } + return } func (port *unixPort) ResetInputBuffer() error {