From dbab9eb6b58f70c6b1644e3275c9050e7f4d0c5e Mon Sep 17 00:00:00 2001 From: Kevin Z Date: Sun, 30 Jun 2024 08:51:54 -0600 Subject: [PATCH] fix port.Read will returns PortClosed error on linux if the buffer size is zero --- serial_unix.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/serial_unix.go b/serial_unix.go index 54e55a8..c480f2b 100644 --- a/serial_unix.go +++ b/serial_unix.go @@ -57,6 +57,10 @@ func (port *unixPort) Close() error { } func (port *unixPort) Read(p []byte) (int, error) { + // If the buffer is empty, instantly returns instead of returns with PortClosed error later + if len(p) == 0 { + return 0, nil + } port.closeLock.RLock() defer port.closeLock.RUnlock() if atomic.LoadUint32(&port.opened) != 1 {