changeset 400:8ba4d2d6c779

Irccd: fix select(2) time conversion
author David Demelier <markand@malikania.fr>
date Wed, 11 Jan 2017 11:50:25 +0100
parents ea688d9ca8b1
children 4ded9be54086
files libcommon/irccd/util.hpp
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libcommon/irccd/util.hpp	Tue Jan 10 20:17:09 2017 +0100
+++ b/libcommon/irccd/util.hpp	Wed Jan 11 11:50:25 2017 +0100
@@ -24,6 +24,8 @@
  * \brief Utilities.
  */
 
+#include <cerrno>
+#include <cstring>
 #include <ctime>
 #include <initializer_list>
 #include <limits>
@@ -705,7 +707,7 @@
 void poll(int timeout, Pollable &first, Rest&... rest)
 {
     fd_set in, out;
-    timeval tv = {0, timeout * 1000};
+    timeval tv = { timeout / 1000, (timeout % 1000) * 1000 };
 
     FD_ZERO(&in);
     FD_ZERO(&out);
@@ -713,8 +715,12 @@
     net::Handle max = 0;
 
     prepare(in, out, max, first, rest...);
-    select(max + 1, &in, &out, nullptr, timeout < 0 ? nullptr : &tv);
-    sync(in, out, first, rest...);
+
+    if (select(max + 1, &in, &out, nullptr, timeout < 0 ? nullptr : &tv) < 0 && errno != EINTR) {
+        throw std::runtime_error(std::strerror(errno));
+    } else {
+        sync(in, out, first, rest...);
+    }
 }
 
 } // !poller