From 55ab7e0b6b814d68157aa83ba69f18135b1ab7c6 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sat, 28 Dec 2019 17:53:11 +0100 Subject: [PATCH] unix: Fix handling of EAGAIN in sp_nonblocking_write(). --- serialport.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/serialport.c b/serialport.c index f9b78bf..4493170 100644 --- a/serialport.c +++ b/serialport.c @@ -952,10 +952,15 @@ SP_API enum sp_return sp_nonblocking_write(struct sp_port *port, /* Returns the number of bytes written, or -1 upon failure. */ ssize_t written = write(port->fd, buf, count); - if (written < 0) - RETURN_FAIL("write() failed"); - else + if (written < 0) { + if (errno == EAGAIN) + // Buffer is full, no bytes written. + RETURN_INT(0); + else + RETURN_FAIL("write() failed"); + } else { RETURN_INT(written); + } #endif }