Optimizations.
This commit is contained in:
parent
7e43656c5c
commit
96d9295df8
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -110,8 +110,8 @@ 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);
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
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");
|
||||
@ -19,10 +19,13 @@ namespace core {
|
||||
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() {
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user