1 parent
df99b6ea7f
commit
d146f11f02
63 files changed
+8331
-2709
No files matched your search
+43
-14
@@ -76,18 +76,12 @@ namespace Echoion::Core
|
||||
// ~ThreadPool then joins every worker.
|
||||
clientPool_.reset();
|
||||
|
||||
// Wait for server thread with timeout
|
||||
// The acceptor was cancelled and ioContext_ stopped above, so the
|
||||
// accept loop exits promptly. Join unconditionally: detaching
|
||||
// here let the thread outlive ioContext_ (use-after-free when the
|
||||
// core library unloads).
|
||||
if (serverThread_.joinable()) {
|
||||
// Give it a moment to clean up
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
while (serverThread_.joinable() &&
|
||||
std::chrono::steady_clock::now() - start <
|
||||
std::chrono::seconds(2)) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
if (serverThread_.joinable()) {
|
||||
serverThread_.detach(); // Force detach if still running
|
||||
}
|
||||
serverThread_.join();
|
||||
}
|
||||
|
||||
if (acceptor_.has_value()) {
|
||||
@@ -120,10 +114,15 @@ namespace Echoion::Core
|
||||
acceptComplete = true;
|
||||
});
|
||||
|
||||
// Poll until accept completes or we're stopped
|
||||
// Block until the accept completes or we're stopped. stop()
|
||||
// clears running_, cancels the acceptor and calls
|
||||
// ioContext_.stop(), so run_one() returns promptly instead of
|
||||
// the previous 10ms busy-poll.
|
||||
while (!acceptComplete.load() && running_.load()) {
|
||||
ioContext_.poll_one();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
if (ioContext_.stopped()) {
|
||||
break;
|
||||
}
|
||||
ioContext_.run_one();
|
||||
}
|
||||
|
||||
// Cancel pending operation if we're stopping
|
||||
@@ -276,6 +275,18 @@ namespace Echoion::Core
|
||||
}
|
||||
}
|
||||
|
||||
// Record the (authorized) invocation in the bounded audit ring.
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(auditMutex_);
|
||||
auditLog_.push_back(AuditEntry{
|
||||
.clientId = clientId,
|
||||
.method = static_cast<int>(request.method),
|
||||
.timestamp = std::chrono::system_clock::now()});
|
||||
if (auditLog_.size() > MAX_AUDIT_ENTRIES) {
|
||||
auditLog_.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
// Find handler
|
||||
std::string methodName =
|
||||
std::to_string(static_cast<int>(request.method));
|
||||
@@ -402,6 +413,24 @@ namespace Echoion::Core
|
||||
handlers_.erase(method);
|
||||
}
|
||||
|
||||
std::vector<RpcServer::AuditEntry> RpcServer::getAuditLog() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(auditMutex_);
|
||||
return {auditLog_.begin(), auditLog_.end()};
|
||||
}
|
||||
|
||||
size_t RpcServer::getClientCount() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(clientsMutex_);
|
||||
return clients_.size();
|
||||
}
|
||||
|
||||
std::chrono::seconds RpcServer::getUptime() const
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(
|
||||
std::chrono::steady_clock::now() - startTime_);
|
||||
}
|
||||
|
||||
void RpcServer::setAuthToken(const std::string& token)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(authMutex_);
|
||||
|
||||
Reference in new issue
Block a user