Continued restructing.

This commit is contained in:
barant committed 2019-09-13 09:16:55 -07:00
1 parent 5e5e626d28
commit a46db126e9
294 files changed
+2455 -2189

No files matched your search

+16 -19
View File
@@ -8,7 +8,7 @@ namespace core {
EPoll::EPoll() : Command() {
Log(LOG_DEBUG_2) << "EPoll object being constructed.";
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPoll object being constructed.";
maxSockets = 1000;
epfd = epoll_create1(0);
@@ -16,17 +16,17 @@ namespace core {
}
EPoll::~EPoll() {
Log(LOG_DEBUG_2) << "BMAEPoll destructed.";
coreutils::Log(coreutils::LOG_DEBUG_2) << "BMAEPoll destructed.";
}
bool EPoll::start(int numberOfThreads, int maxSockets) {
Log(LOG_DEBUG_2) << "Starting epoll event processing.";
coreutils::Log(coreutils::LOG_DEBUG_2) << "Starting epoll event processing.";
this->numberOfThreads = numberOfThreads;
Log(LOG_DEBUG_3) << "Number of threads starting is " << numberOfThreads << ".";
Log(LOG_DEBUG_3) << "Maximum connections is " << maxSockets << ".";
coreutils::Log(coreutils::LOG_DEBUG_3) << "Number of threads starting is " << numberOfThreads << ".";
coreutils::Log(coreutils::LOG_DEBUG_3) << "Maximum connections is " << maxSockets << ".";
// TODO: Set the number of maximum open files to the maxSockets value.
//
@@ -37,10 +37,10 @@ namespace core {
//----------------------------------------------------------------------
for(int ix = 0; ix < numberOfThreads; ++ix)
threads.emplace_back(*this);
threads.emplace_back(*this);
for(int ix = 0; ix < numberOfThreads; ++ix)
threads[ix].start();
threads[ix].start();
return true;
}
@@ -54,7 +54,7 @@ namespace core {
//--------------------------------------------------------
for(int ix = 0; ix < numberOfThreads; ++ix)
threads[ix].join();
threads[ix].join();
//--------------------------
// Close the epoll socket.
@@ -73,8 +73,8 @@ namespace core {
lock.lock();
std::map<int, Socket *>::iterator temp = sockets.find(socket->getDescriptor());
if(temp != sockets.end())
throw Exception("Attempt to register socket that is already registered.");
Log(LOG_DEBUG_3) << "Registering socket " << socket->getDescriptor() << ".";
throw coreutils::Exception("Attempt to register socket that is already registered.");
coreutils::Log(coreutils::LOG_DEBUG_3) << "Registering socket " << socket->getDescriptor() << ".";
sockets.insert(std::pair<int, Socket *>(socket->getDescriptor(), socket));
lock.unlock();
socket->enable(true);
@@ -85,10 +85,10 @@ namespace core {
bool EPoll::unregisterSocket(Socket *socket /**< The Socket to unregister. */) {
lock.lock();
socket->enable(false);
Log(LOG_DEBUG_3) << "Unregistering socket " << socket->getDescriptor() << ".";
coreutils::Log(coreutils::LOG_DEBUG_3) << "Unregistering socket " << socket->getDescriptor() << ".";
std::map<int, Socket *>::iterator temp = sockets.find(socket->getDescriptor());
if(temp == sockets.end())
throw Exception("Attempt to unregister socket that is not registered.");
throw coreutils::Exception("Attempt to unregister socket that is not registered.");
sockets.erase(temp);
lock.unlock();
socket->onUnregistered();
@@ -100,10 +100,10 @@ namespace core {
std::map<int, Socket *>::iterator socket = sockets.find(event.data.fd);
lock.unlock();
if(socket != sockets.end()) {
(socket->second)->eventReceived(event);
(socket->second)->eventReceived(event);
} else {
Log(LOG_WARN) << "System problem. Reference to socket " << event.data.fd << " that has no object.";
throw Exception("System problem occurred.");
coreutils::Log(coreutils::LOG_WARN) << "System problem. Reference to socket " << event.data.fd << " that has no object.";
throw coreutils::Exception("System problem occurred.");
}
}
@@ -112,12 +112,9 @@ namespace core {
}
int EPoll::processCommand(std::string command, Session *session, std::stringstream &data) {
int sequence = 0;
int sequence = 0;
for(auto threadx : threads) {
data << "|" << ++sequence;
data << "|" ;
threadx.output(data);
data << "|" << std::endl;
}