]> sigrok.org Git - libserialport.git/commitdiff
posix: Consistent debug output when blocking operations time out.
authorMartin Ling <redacted>
Thu, 7 May 2015 08:41:41 +0000 (09:41 +0100)
committerUwe Hermann <redacted>
Wed, 27 May 2015 09:09:25 +0000 (11:09 +0200)
serialport.c

index 35b6ac54fe20b067701be9d212f4d864de2e2df8..c77682f98566fcf903e8aa76689949cdc4b8523c 100644 (file)
@@ -795,10 +795,9 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
                /* Wait until space is available. */
                if (timeout_ms) {
                        gettimeofday(&now, NULL);
-                       if (timercmp(&now, &end, >)) {
-                               DEBUG("Write timed out");
-                               RETURN_INT(bytes_written);
-                       }
+                       if (timercmp(&now, &end, >))
+                               /* Timeout has expired. */
+                               break;
                        timersub(&end, &now, &delta);
                }
                result = select(port->fd + 1, NULL, &fds, NULL, timeout_ms ? &delta : NULL);
@@ -810,8 +809,8 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
                                RETURN_FAIL("select() failed");
                        }
                } else if (result == 0) {
-                       DEBUG("Write timed out");
-                       RETURN_INT(bytes_written);
+                       /* Timeout has expired. */
+                       break;
                }
 
                /* Do write. */
@@ -830,6 +829,9 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
                ptr += result;
        }
 
+       if (bytes_written < count)
+               DEBUG("Write timed out");
+
        RETURN_INT(bytes_written);
 #endif
 }
@@ -1013,7 +1015,7 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
                        gettimeofday(&now, NULL);
                        if (timercmp(&now, &end, >))
                                /* Timeout has expired. */
-                               RETURN_INT(bytes_read);
+                               break;
                        timersub(&end, &now, &delta);
                }
                result = select(port->fd + 1, &fds, NULL, NULL, timeout_ms ? &delta : NULL);
@@ -1025,8 +1027,8 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
                                RETURN_FAIL("select() failed");
                        }
                } else if (result == 0) {
-                       DEBUG("Read timed out");
-                       RETURN_INT(bytes_read);
+                       /* Timeout has expired. */
+                       break;
                }
 
                /* Do read. */
@@ -1045,6 +1047,9 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
                ptr += result;
        }
 
+       if (bytes_read < count)
+               DEBUG("Read timed out");
+
        RETURN_INT(bytes_read);
 #endif
 }