Skip to content

Commit

Permalink
ews: switch high_resolution_clock to steady_clock
Browse files Browse the repository at this point in the history
high_resolution_clock, in practice, is just a typedef to either
system_clock or steady_clock. Be explicit about what we want: for
age, a "stopwatch" is good enough.

[Under GNU stdlibc++ 14, the granularity of system_clock and
steady_clock is the same, and high_resolution_clock is aliased to
system_clock. Under clang libc++ however, system_clock has just a
coarse 1µs granularity vs. steady_clock's 1ns, and
high_resolution_clock is aliased to steady_clock.]
  • Loading branch information
jengelh committed Sep 25, 2024
1 parent 9905b29 commit cae62d0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions exch/ews/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,9 @@ void Cleaner::operator()(MESSAGE_CONTENT *x) {message_content_free(x);}

EWSContext::EWSContext(int id, HTTP_AUTH_INFO ai, const char *data, uint64_t length,
EWSPlugin &p) :
m_ID(id),
m_orig(*get_request(id)),
m_auth_info(ai),
m_request(data, length),
m_response(p.server_version()),
m_plugin(p)
m_ID(id), m_orig(*get_request(id)), m_auth_info(ai),
m_request(data, length), m_response(p.server_version()), m_plugin(p),
m_created(tp_now())
{
tinyxml2::XMLElement* imp = nullptr;
if(m_request.header && (imp = m_request.header->FirstChildElement("ExchangeImpersonation")) &&
Expand All @@ -346,7 +343,9 @@ EWSContext::~EWSContext()
}

double EWSContext::age() const
{return std::chrono::duration<double>(std::chrono::high_resolution_clock::now()-m_created).count();}
{
return std::chrono::duration<double>(tp_now() - m_created).count();
}

/**
* @brief Copy string to context allocated buffer
Expand Down
6 changes: 3 additions & 3 deletions exch/ews/ews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ struct EWSPlugin::DebugCtx
std::mutex requestLock{};
std::mutex hashLock{};
std::unordered_map<uint64_t, size_t> requestHashes; ///< How often a request with this hash value occurred
std::chrono::high_resolution_clock::time_point last;
std::chrono::high_resolution_clock::duration minRequestTime{};
gromox::time_point last{};
gromox::time_duration minRequestTime{};
uint32_t loopThreshold = 0; ///< How many request repetitions to ignore before warning
uint8_t flags = 0;
};
Expand Down Expand Up @@ -334,7 +334,7 @@ http_status EWSPlugin::dispatch(int ctx_id, HTTP_AUTH_INFO& auth_info, const voi
lockProxy = std::unique_lock<std::mutex>(debug->requestLock);
if(debug->flags & DebugCtx::FL_RATELIMIT)
{
auto now = std::chrono::high_resolution_clock::now();
auto now = tp_now();
std::this_thread::sleep_for(debug->last-now+debug->minRequestTime);
debug->last = now;
}
Expand Down
2 changes: 1 addition & 1 deletion exch/ews/ews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class EWSContext {
EWSPlugin& m_plugin;
std::string impersonationUser; ///< Buffer to hold username of impersonated user
std::string impersonationMaildir; ///< Buffer to hold maildir of impersonated user
std::chrono::high_resolution_clock::time_point m_created = std::chrono::high_resolution_clock::now();
gromox::time_point m_created{};
std::unique_ptr<NotificationContext> m_notify;
};

Expand Down

0 comments on commit cae62d0

Please sign in to comment.