]> sigrok.org Git - libserialport.git/blobdiff - serialport.c
Build: Include config.h first in all source files
[libserialport.git] / serialport.c
index da292ac650ffff5e1099733fe58271cf16b60248..7b45229cca8281abf2cd9b1173ad031376ed8a76 100644 (file)
@@ -2,8 +2,8 @@
  * This file is part of the libserialport project.
  *
  * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
- * Copyright (C) 2010-2012 Uwe Hermann <uwe@hermann-uwe.de>
- * Copyright (C) 2013 Martin Ling <martin-libserialport@earth.li>
+ * Copyright (C) 2010-2015 Uwe Hermann <uwe@hermann-uwe.de>
+ * Copyright (C) 2013-2015 Martin Ling <martin-libserialport@earth.li>
  * Copyright (C) 2013 Matthias Heidbrink <m-sigrok@heidbrink.biz>
  * Copyright (C) 2014 Aurelien Jacobs <aurel@gnuage.org>
  *
@@ -21,6 +21,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include "libserialport.h"
 #include "libserialport_internal.h"
 
@@ -1457,7 +1458,11 @@ SP_API enum sp_return sp_wait(struct sp_event_set *event_set,
                 * to avoid any issues if a short timeout is reached before
                 * poll() is even run.
                 */
-               if (timeout_ms && started) {
+               if (!timeout_ms) {
+                       timeout_remaining_ms = -1;
+               } else if (!started) {
+                       timeout_remaining_ms = timeout_ms;
+               } else {
                        gettimeofday(&now, NULL);
                        if (timercmp(&now, &end, >)) {
                                DEBUG("Wait timed out");
@@ -1467,7 +1472,7 @@ SP_API enum sp_return sp_wait(struct sp_event_set *event_set,
                        timeout_remaining_ms = delta.tv_sec * 1000 + delta.tv_usec / 1000;
                }
 
-               result = poll(pollfds, event_set->count, timeout_ms ? timeout_remaining_ms : -1);
+               result = poll(pollfds, event_set->count, timeout_remaining_ms);
                started = 1;
 
                if (result < 0) {