Optimizations.

This commit is contained in:
Brad Arant 2021-09-23 16:28:32 -07:00
parent 7e43656c5c
commit 96d9295df8
7 changed files with 34 additions and 30 deletions

View File

@ -3,7 +3,7 @@
namespace core { namespace core {
CommandList::CommandList(std::string delimiter) : delimiter(delimiter) {} CommandList::CommandList(std::string delimiter, int depth) : delimiter(delimiter), depth(depth) {}
void CommandList::add(Command &command, std::string name) { void CommandList::add(Command &command, std::string name) {
commands.insert(std::make_pair(name, &command)); commands.insert(std::make_pair(name, &command));
@ -18,7 +18,7 @@ namespace core {
if(request.equals("")) if(request.equals(""))
return false; return false;
request.split(delimiter); request.split(delimiter);
auto command = commands.find(request[0].str())->second; auto command = commands[request[0].str()];
return command->processCommand(request, session); return command->processCommand(request, session);
} }
return false; return false;

View File

@ -19,7 +19,7 @@ namespace core {
public: public:
CommandList(std::string delimiter = ""); CommandList(std::string delimiter = "", int depth = 0);
/// ///
/// Add a new command to the command list and assign a default search value. /// Add a new command to the command list and assign a default search value.
@ -70,6 +70,7 @@ namespace core {
std::map<std::string, Command *> commands; std::map<std::string, Command *> commands;
std::string delimiter; std::string delimiter;
int depth;
}; };

View File

@ -5,7 +5,7 @@
namespace core { namespace core {
ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address) : TCPServer(ePoll, address, " ", "Console Server") { ConsoleServer::ConsoleServer(EPoll &ePoll, IPAddress address) : TCPServer(ePoll, address, " ", 10, "Console Server") {
coreutils::Log(this); coreutils::Log(this);
} }

View File

@ -110,8 +110,8 @@ namespace core {
int len; int len;
int error = -1; int error = -1;
for(int ix = 0; ix < buffer.getLength(); ++ix) // for(int ix = 0; ix < buffer.getLength(); ++ix)
buffer[ix] = 0; // buffer[ix] = 0;
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) { if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
coreutils::ZString zbuffer(buffer.getData(), len); coreutils::ZString zbuffer(buffer.getData(), len);

View File

@ -6,8 +6,8 @@
namespace core { namespace core {
TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, std::string text) TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text)
: TCPSocket(ePoll, text), commands(delimiter) { : TCPSocket(ePoll, text), commands(delimiter, depth) {
commands.add(subscriptions, "publish"); commands.add(subscriptions, "publish");
commands.add(subscriptions, "unpublish"); commands.add(subscriptions, "unpublish");
@ -19,10 +19,13 @@ namespace core {
setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
int yes = 1; int yes = 1;
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0) if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0)
throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno)); throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno));
if(listen(getDescriptor(), 20) < 0) if(listen(getDescriptor(), 20) < 0)
throw coreutils::Exception("Error on listen to socket"); throw coreutils::Exception("Error on listen to socket");
} }
TCPServer::~TCPServer() { TCPServer::~TCPServer() {

View File

@ -35,7 +35,7 @@ namespace core {
/// @param commandName the name of the command used to invoke the status display for this object. /// @param commandName the name of the command used to invoke the status display for this object.
/// ///
TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter = " ", std::string text = ""); TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter = " ", int depth = 10, std::string text = "");
/// ///
/// The destructor for this object. /// The destructor for this object.