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 {
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) {
commands.insert(std::make_pair(name, &command));
@ -18,7 +18,7 @@ namespace core {
if(request.equals(""))
return false;
request.split(delimiter);
auto command = commands.find(request[0].str())->second;
auto command = commands[request[0].str()];
return command->processCommand(request, session);
}
return false;

View File

@ -19,7 +19,7 @@ namespace core {
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.
@ -70,6 +70,7 @@ namespace core {
std::map<std::string, Command *> commands;
std::string delimiter;
int depth;
};

View File

@ -5,7 +5,7 @@
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);
}

View File

@ -4,14 +4,14 @@
#include "includes"
namespace core {
class Object {
public:
std::string name;
std::string tag;
};
}

View File

@ -110,19 +110,19 @@ namespace core {
int len;
int error = -1;
for(int ix = 0; ix < buffer.getLength(); ++ix)
buffer[ix] = 0;
// for(int ix = 0; ix < buffer.getLength(); ++ix)
// buffer[ix] = 0;
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
coreutils::ZString zbuffer(buffer.getData(), len);
onDataReceived(zbuffer);
}
else {
error = errno;
switch (error) {
// When a listening socket receives a connection
// request we get one of these.
//

View File

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

View File

@ -35,7 +35,7 @@ namespace core {
/// @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.