Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/sendspin/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ class SendspinServer {
/// and after its source's open stream is reported stopped.
void stop();

/// @brief The clock of every timestamp the server sends, in microseconds: monotonic, and
/// counting through system sleep
/// @brief The clock of every timestamp the server sends, in microseconds: monotonic, at the
/// clock's own rate, never slewed by NTP
int64_t now_us() const;

/// @brief The server_id clients see (spec connection.md "Identities"); empty while stopped
Expand Down
5 changes: 5 additions & 0 deletions src/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ int64_t now_us() {
int64_t now_us() {
constexpr int64_t US_PER_S = 1000000;
timespec ts{};
#if defined(__linux__)
// A slewed clock would change rate under the clients' time filters
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
Comment thread
kahrendt marked this conversation as resolved.
Resolved
Comment thread
kahrendt marked this conversation as resolved.
Resolved
#else
clock_gettime(CLOCK_MONOTONIC, &ts);
#endif
return (static_cast<int64_t>(ts.tv_sec) * US_PER_S) + (ts.tv_nsec / NS_PER_US);
}

Expand Down
5 changes: 3 additions & 2 deletions src/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

namespace sendspin::server {

/// @brief Monotonic microseconds that keep counting while the system sleeps: `CLOCK_MONOTONIC`
/// on Linux, `mach_continuous_time` on macOS (whose `steady_clock` stops during sleep)
/// @brief Monotonic microseconds at the clock's own rate, never slewed by NTP:
/// `CLOCK_MONOTONIC_RAW` on Linux, `mach_continuous_time` on macOS (which keeps counting while the
/// system sleeps), the esp_timer's `CLOCK_MONOTONIC` on ESP-IDF
int64_t now_us();

} // namespace sendspin::server
2 changes: 1 addition & 1 deletion src/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class Timer {
Timer& operator=(const Timer&) = delete;

/// @brief Calls on_fire from the loop once now_us() reaches about at_us, replacing any
/// pending call. The wait runs on the steady clock, which can fall behind now_us().
/// pending call. The wait runs on the steady clock, which can drift from now_us().
void start(int64_t at_us, std::function<void()> on_fire);

void cancel();
Expand Down
Loading