tls and master diverged from a July 2024 fork point and never reconciled - tls carries ~19 months of real socket/TLS stability fixes (uninitialized tlsInfo, TCPServer::connectionRequest() unconditionally initializing TLS, the WANT_READ write busy-spin, the console authentication fix from this session), while master independently picked up a Subscription/SubscriptionManager rework (MString-based ownership tracking: owner/ownership/selection/time fields and a working subscriptionOwner() method) that tls never had. Every file both branches touched was resolved by keeping tls's side entirely (Command.h, Socket.cpp, TCPServer.h, TCPSession.cpp/h, TCPSocket.h were pure reformatting on master's side, or an alternate/superseded fix for a bug tls already fixed a different way - e.g. master's TCPSession uuid/alias handling vs tls's existing uuid_unparse-based fix), with two deliberate exceptions: - TCPServer.cpp's constructor was missing the commands.add(subscriptions, "publish"/"subscribe"/"catalog"/...) wiring master had - without it, SubscriptionManager existed but was completely unreachable through the normal command dispatch. Restored on top of tls's TLS-aware constructor. - SubscriptionManager.cpp's "invite" command handler had a real incompatibility: master's version assigned into an `invitee` member typed as coreutils::MString via a stray `(coreutils::MString *)` cast that doesn't match the member's actual (non-pointer) type, and called session.server.getSessionByAlias() against a TCPServer reference - tls made TCPSession::server a pointer (part of removing the separate TCPSession2 class), so that call site no longer compiles as written. Took tls's cleaner local-variable version instead (functionally identical - looks up a session by alias and forwards an invite message) and removed the now-unused `invitee` member from SubscriptionManager.h. One additional compile fix needed after resolving conflicts: Subscription::subscriptionOwners is an MString (master's ownership design), but TCPSession::alias is void* (tls's identity mechanism, unchanged and depended on elsewhere) - MString has an implicit constructor from void* already used successfully elsewhere in this same file (the "publish" handler's Subscription constructor call), but operator== doesn't accept the same implicit conversion, so removeSessionSubscriptions()'s ownership check needed an explicit coreutils::MString(session.alias) construction to compile. Also drops output/main (a stray checked-in compiled binary, already removed on tls) and the doxygen docs/html output (already removed on tls, was carried on master since the fork). Verified: full ServerCore rebuild (./compile) succeeds with zero errors or warnings beyond the one compile fix documented above.
70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
#include "Timer.h"
|
|
#include <sys/timerfd.h>
|
|
#include <math.h>
|
|
|
|
namespace core
|
|
{
|
|
|
|
Timer::Timer(EPoll &ePoll, double delay = 0.0f) : Socket(ePoll, "Timer")
|
|
{
|
|
setDescriptor(timerfd_create(CLOCK_REALTIME, 0));
|
|
setTimer(delay);
|
|
}
|
|
|
|
Timer::~Timer()
|
|
{
|
|
}
|
|
|
|
void Timer::setTimer(double delay)
|
|
{
|
|
|
|
double integer;
|
|
double fraction;
|
|
struct itimerspec timer;
|
|
|
|
delayValue = delay;
|
|
|
|
timer.it_interval.tv_sec = 0;
|
|
timer.it_interval.tv_nsec = 0;
|
|
|
|
fraction = modf(delay, &integer);
|
|
|
|
timer.it_value.tv_sec = (int)integer;
|
|
timer.it_value.tv_nsec = (int)(fraction * 1000000000);
|
|
|
|
timerfd_settime(getDescriptor(), 0, &timer, NULL);
|
|
}
|
|
|
|
void Timer::clearTimer()
|
|
{
|
|
|
|
struct itimerspec timer;
|
|
|
|
timer.it_interval.tv_sec = 0;
|
|
timer.it_interval.tv_nsec = 0;
|
|
timer.it_value.tv_sec = 0;
|
|
timer.it_value.tv_nsec = 0;
|
|
|
|
timerfd_settime(getDescriptor(), 0, &timer, NULL);
|
|
}
|
|
|
|
double Timer::getElapsed()
|
|
{
|
|
struct itimerspec timer;
|
|
timerfd_gettime(getDescriptor(), &timer);
|
|
double toTimeout = (double)((timer.it_value.tv_sec * 1000000000L) + timer.it_value.tv_nsec) / 1000000000L;
|
|
return delayValue - toTimeout;
|
|
}
|
|
|
|
void Timer::onDataReceived(std::string data)
|
|
{
|
|
onTimeout();
|
|
}
|
|
|
|
double Timer::getEpoch()
|
|
{
|
|
return (double)std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count() / 1000000000L;
|
|
}
|
|
|
|
}
|