diff options
author | Mattias Andrée <maandree@kth.se> | 2016-07-11 16:29:27 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-07-11 16:29:27 +0200 |
commit | 93c22493e847fa074d62fd7d8f7d618a19690db0 (patch) | |
tree | b661ca450e19d3e38e04ef3802e8952ff997197b /src/util.c | |
parent | Place in background unless -f (diff) | |
download | coopgammad-93c22493e847fa074d62fd7d8f7d618a19690db0.tar.gz coopgammad-93c22493e847fa074d62fd7d8f7d618a19690db0.tar.bz2 coopgammad-93c22493e847fa074d62fd7d8f7d618a19690db0.tar.xz |
Create and listen to socket + do not use deprecated usleep
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -21,6 +21,7 @@ #include <errno.h> #include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> @@ -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); +} + |