#include "ConsoleServer.h" #include "ConsoleSession.h" #include "Command.h" #include "Log.h" namespace core { ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo, std::function credentialChecker) : TCPServer(ePoll, address, tlsInfo, " ", 10, "Console Server"), credentialChecker(credentialChecker) { coreutils::Log(this); } void ConsoleServer::logSend(std::string out) { // Was unlocked entirely (and iterated raw pointers before // TCPServer::sessions became shared_ptr-owned - see its own doc // comment) despite connectionRequest()/removeFromSessionList() // both mutating this same vector under `lock` from other threads. std::lock_guard guard(lock); for(auto &session : sessions) ((ConsoleSession *)session.get())->writeLog(out); } TCPSession * ConsoleServer::getSocketAccept(EPoll &ePoll) { return new ConsoleSession(ePoll, this); } bool ConsoleServer::checkCredentials(std::string user, std::string password) { return credentialChecker ? credentialChecker(user, password) : true; } }