From 93c22493e847fa074d62fd7d8f7d618a19690db0 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 11 Jul 2016 16:29:27 +0200 Subject: Create and listen to socket + do not use deprecated usleep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/util.c') diff --git a/src/util.c b/src/util.c index 715aa6b..81926c6 100644 --- a/src/util.c +++ b/src/util.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -133,3 +134,21 @@ int dup2atleast(int fd, int atleast) return new; } + +/** + * Perform a timed suspention of the process. + * The process resumes when the timer expires, + * or when it is interrupted. + * + * @param ms The number of milliseconds to sleep, + * must be less than 1000 + */ +void msleep(int ms) +{ + struct timespec ts; + ts.tv_sec = 0; + ts.tv_nsec = (long)ms * 1000000L; + if (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL) == ENOTSUP) + nanosleep(&ts, NULL); +} + -- cgit v1.2.3-70-g09d2