]> sigrok.org Git - libserialport.git/commitdiff
posix: Move FD_ZERO() and FD_SET() calls outside loops.
authorMartin Ling <redacted>
Thu, 7 May 2015 08:41:02 +0000 (09:41 +0100)
committerUwe Hermann <redacted>
Wed, 27 May 2015 09:09:25 +0000 (11:09 +0200)
serialport.c

index 39500f8f93fa699e17c5b13bf6292551ae388198..35b6ac54fe20b067701be9d212f4d864de2e2df8 100644 (file)
@@ -787,11 +787,12 @@ SP_API enum sp_return sp_blocking_write(struct sp_port *port, const void *buf,
                timeradd(&start, &delta, &end);
        }
 
+       FD_ZERO(&fds);
+       FD_SET(port->fd, &fds);
+
        /* Loop until we have written the requested number of bytes. */
        while (bytes_written < count) {
                /* Wait until space is available. */
-               FD_ZERO(&fds);
-               FD_SET(port->fd, &fds);
                if (timeout_ms) {
                        gettimeofday(&now, NULL);
                        if (timercmp(&now, &end, >)) {
@@ -1002,11 +1003,12 @@ SP_API enum sp_return sp_blocking_read(struct sp_port *port, void *buf,
                timeradd(&start, &delta, &end);
        }
 
+       FD_ZERO(&fds);
+       FD_SET(port->fd, &fds);
+
        /* Loop until we have the requested number of bytes. */
        while (bytes_read < count) {
                /* Wait until data is available. */
-               FD_ZERO(&fds);
-               FD_SET(port->fd, &fds);
                if (timeout_ms) {
                        gettimeofday(&now, NULL);
                        if (timercmp(&now, &end, >))