]> sigrok.org Git - libserialport.git/commitdiff
unix: Fix handling of EAGAIN in sp_nonblocking_write().
authorMartin Ling <redacted>
Sat, 28 Dec 2019 16:53:11 +0000 (17:53 +0100)
committerUwe Hermann <redacted>
Sat, 28 Dec 2019 19:43:22 +0000 (20:43 +0100)
serialport.c

index f9b78bf0fee09d2d78e7c5dbb0193c2bec8d8acb..449317052704e87a5f8038b0f50ea1399d097115 100644 (file)
@@ -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
 }