From 772c586133ec5e069233bac08a0bb0e86b36a6e8 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Thu, 7 May 2015 09:41:02 +0100 Subject: [PATCH] posix: Move FD_ZERO() and FD_SET() calls outside loops. --- serialport.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/serialport.c b/serialport.c index 39500f8..35b6ac5 100644 --- a/serialport.c +++ b/serialport.c @@ -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, >))