Skip to content

Commit

Permalink
FIx for maxOS and OpenBSD
Browse files Browse the repository at this point in the history
Closes #33
  • Loading branch information
rigtorp committed Sep 25, 2023
1 parent 52bd71d commit 1e100fd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/udpreplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,25 @@ int main(int argc, char *argv[]) {

if (deadline.tv_sec > now.tv_sec ||
(deadline.tv_sec == now.tv_sec && deadline.tv_nsec > now.tv_nsec)) {
#if _POSIX_C_SOURCE >= 200112L
if (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &deadline,
nullptr) == -1) {
std::cerr << "clock_nanosleep: " << strerror(errno) << std::endl;
return 1;
}
#else
timespec duration;
duration.tv_sec = deadline.tv_sec - now.tv_sec;
duration.tv_nsec = deadline.tv_nsec - now.tv_nsec;
if (duration.tv_nsec < 0) {
--duration.tv_sec;
duration.tv_nsec += 1000000000L;
}
if (nanosleep(&duration, nullptr) == -1) {
std::cerr << "nanosleep: " << strerror(errno) << std::endl;
return 1;
}
#endif
}

#ifdef __GLIBC__
Expand Down

0 comments on commit 1e100fd

Please sign in to comment.