Optimizations.
This commit is contained in:
parent
7e43656c5c
commit
96d9295df8
@ -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;
|
||||||
|
@ -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;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
Object.h
8
Object.h
@ -4,14 +4,14 @@
|
|||||||
#include "includes"
|
#include "includes"
|
||||||
|
|
||||||
namespace core {
|
namespace core {
|
||||||
|
|
||||||
class Object {
|
class Object {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string tag;
|
std::string tag;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
Socket.cpp
10
Socket.cpp
@ -110,19 +110,19 @@ 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);
|
||||||
onDataReceived(zbuffer);
|
onDataReceived(zbuffer);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
error = errno;
|
error = errno;
|
||||||
|
|
||||||
switch (error) {
|
switch (error) {
|
||||||
|
|
||||||
// When a listening socket receives a connection
|
// When a listening socket receives a connection
|
||||||
// request we get one of these.
|
// request we get one of these.
|
||||||
//
|
//
|
||||||
|
@ -6,24 +6,27 @@
|
|||||||
|
|
||||||
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");
|
||||||
commands.add(subscriptions, "subscribe");
|
commands.add(subscriptions, "subscribe");
|
||||||
commands.add(subscriptions, "unsubscribe");
|
commands.add(subscriptions, "unsubscribe");
|
||||||
commands.add(subscriptions, "catalog");
|
commands.add(subscriptions, "catalog");
|
||||||
commands.add(subscriptions, "event");
|
commands.add(subscriptions, "event");
|
||||||
|
|
||||||
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)
|
|
||||||
throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno));
|
if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0)
|
||||||
if(listen(getDescriptor(), 20) < 0)
|
throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno));
|
||||||
throw coreutils::Exception("Error on listen to socket");
|
|
||||||
}
|
if(listen(getDescriptor(), 20) < 0)
|
||||||
|
throw coreutils::Exception("Error on listen to socket");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TCPServer::~TCPServer() {
|
TCPServer::~TCPServer() {
|
||||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "Closing server socket " << getDescriptor() << ".";
|
||||||
|
@ -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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user