Integrate the monitor's listener socket into the shard's poll()

This removes the need for a separate monitor thread.
This commit is contained in:
2020-12-06 01:44:37 +01:00
parent 53d8cb67ba
commit 92307063fc
7 changed files with 44 additions and 30 deletions

View File

@@ -6,6 +6,7 @@
#include "CNShared.hpp"
#include "settings.hpp"
#include "Database.hpp"
#include "Monitor.hpp"
#include "TableData.hpp" // for flush()
#include <iostream>
@@ -21,6 +22,9 @@ CNShardServer::CNShardServer(uint16_t p) {
REGISTER_SHARD_TIMER(keepAliveTimer, 4000);
REGISTER_SHARD_TIMER(periodicSaveTimer, settings::DBSAVEINTERVAL*1000);
init();
if (settings::MONITORENABLED)
fds.push_back({Monitor::init(), POLLIN});
}
void CNShardServer::handlePacket(CNSocket* sock, CNPacketData* data) {
@@ -62,6 +66,10 @@ void CNShardServer::periodicSaveTimer(CNServer* serv, time_t currTime) {
std::cout << "[INFO] Done." << std::endl;
}
bool CNShardServer::checkExtraSockets(int i) {
return Monitor::acceptConnection(fds[i].fd, fds[i].revents);
}
void CNShardServer::newConnection(CNSocket* cns) {
cns->setActiveKey(SOCKETKEY_E); // by default they accept keys encrypted with the default key
}