tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

commit 78a7a6e2525f4a22253ddc3dcd2ce7df7d819591
parent d727eb21e5363a193171d2eea236fb5604719bb2
Author: Waldemar Zimpel <w.zimpel@dev.utilizer.de>
Date:   Thu, 28 Aug 2025 01:24:50 +0200

Preparation of `tor_sleep_msec()`

- Update `tor_sleep_msec()` with `nanosleep()` function
- Make `tor_sleep_msec()` available outside of unit tests

Diffstat:
Msrc/lib/time/compat_time.c | 9+++++----
Msrc/lib/time/compat_time.h | 4++--
2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/lib/time/compat_time.c b/src/lib/time/compat_time.c @@ -1,6 +1,6 @@ /* Copyright (c) 2003-2004, Roger Dingledine * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. - * Copyright (c) 2007-2021, The Tor Project, Inc. */ + * Copyright (c) 2007-2025, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** @@ -53,13 +53,15 @@ #undef HAVE_CLOCK_GETTIME #endif -#ifdef TOR_UNIT_TESTS -/** Delay for <b>msec</b> milliseconds. Only used in tests. */ +/** Delay for <b>msec</b> milliseconds. */ void tor_sleep_msec(int msec) { #ifdef _WIN32 Sleep(msec); +#elif defined(HAVE_TIME_H) + struct timespec ts = {msec / 1000, (msec % 1000) * 1000 * 1000}; + while (nanosleep(&ts, &ts) == -1 && errno == EINTR); #elif defined(HAVE_USLEEP) sleep(msec / 1000); /* Some usleep()s hate sleeping more than 1 sec */ @@ -71,7 +73,6 @@ tor_sleep_msec(int msec) sleep(CEIL_DIV(msec, 1000)); #endif /* defined(_WIN32) || ... */ } -#endif /* defined(TOR_UNIT_TESTS) */ #define ONE_MILLION ((int64_t) (1000 * 1000)) #define ONE_BILLION ((int64_t) (1000 * 1000 * 1000)) diff --git a/src/lib/time/compat_time.h b/src/lib/time/compat_time.h @@ -1,6 +1,6 @@ /* Copyright (c) 2003-2004, Roger Dingledine * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. - * Copyright (c) 2007-2021, The Tor Project, Inc. */ + * Copyright (c) 2007-2025, The Tor Project, Inc. */ /* See LICENSE for licensing information */ /** @@ -361,9 +361,9 @@ monotime_coarse_diff_msec32(const monotime_coarse_t *start, #endif /* SIZEOF_VOID_P == 8 */ } -#ifdef TOR_UNIT_TESTS void tor_sleep_msec(int msec); +#ifdef TOR_UNIT_TESTS void monotime_enable_test_mocking(void); void monotime_disable_test_mocking(void); void monotime_set_mock_time_nsec(int64_t);