diff --git a/CommandList.cpp b/CommandList.cpp index 9c22744..23a30b5 100644 --- a/CommandList.cpp +++ b/CommandList.cpp @@ -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; diff --git a/CommandList.h b/CommandList.h index 061f84f..5d62707 100644 --- a/CommandList.h +++ b/CommandList.h @@ -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 commands; std::string delimiter; + int depth; }; diff --git a/ConsoleServer.cpp b/ConsoleServer.cpp index 93a13dc..8160498 100644 --- a/ConsoleServer.cpp +++ b/ConsoleServer.cpp @@ -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); } diff --git a/Object.h b/Object.h index d37e87a..c95692f 100644 --- a/Object.h +++ b/Object.h @@ -4,14 +4,14 @@ #include "includes" namespace core { - + class Object { - + public: - + std::string name; std::string tag; - + }; } diff --git a/Socket.cpp b/Socket.cpp index ba4ce6f..5e05ccf 100644 --- a/Socket.cpp +++ b/Socket.cpp @@ -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. // diff --git a/TCPServer.cpp b/TCPServer.cpp index d75819d..9bacc86 100644 --- a/TCPServer.cpp +++ b/TCPServer.cpp @@ -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() << "."; diff --git a/TCPServer.h b/TCPServer.h index aad7a2c..0bd3a1c 100644 --- a/TCPServer.h +++ b/TCPServer.h @@ -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.