From: Martin Ling Date: Sat, 28 Dec 2019 16:53:11 +0000 (+0100) Subject: unix: Fix handling of EAGAIN in sp_nonblocking_write(). X-Git-Tag: libserialport-0.1.2~89 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=55ab7e0b6b814d68157aa83ba69f18135b1ab7c6;p=libserialport.git unix: Fix handling of EAGAIN in sp_nonblocking_write(). --- 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 }