A commit before I change everything on the the way events are handled.

This commit is contained in:
Brad Arant committed 2020-04-25 08:19:26 -07:00
1 parent 28292e924a
commit 796ddd511f
7 files changed
+65 -41

No files matched your search

+15 -16
View File
@@ -60,21 +60,24 @@ namespace core {
bool Socket::eventReceived(struct epoll_event event, int threadId) {
coreutils::Log(coreutils::LOG_DEBUG_1) << "eventReceived on " << descriptor << "; shutDown = " << shutDown << "; active = " << active << ";";
// coreutils::Log(coreutils::LOG_DEBUG_2) << "waiting for lock on socket " << descriptor << ".";
lock.lock();
// lock.lock();
// coreutils::Log(coreutils::LOG_DEBUG_2) << "Obtained lock on socket " << descriptor << ".";
if(event.events & EPOLLRDHUP) {
coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLRDHUP " << descriptor;
readHangup = true;
shutdown("hangup received");
lock.unlock();
// lock.unlock();
// coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << ". RDHUP";
return false;
}
if(event.events & EPOLLIN) {
coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLIN " << descriptor;
receiveData(buffer, length);
ePoll.resetRead(this);
}
if(event.events & EPOLLWRNORM) {
@@ -84,16 +87,16 @@ namespace core {
if(event.events & EPOLLHUP) {
coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLHUP " << descriptor;
coreutils::Log(coreutils::LOG_DEBUG_1) << "end shutting down" << descriptor;
shutdown();
lock.unlock();
// lock.unlock();
// coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << ". HUP";
return false;
}
coreutils::Log(coreutils::LOG_DEBUG_1) << "end with active = " << active << " on socket " << descriptor;
lock.unlock();
// lock.unlock();
// coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << " with reset " << reset << ".";
return active;
return reset;
}
void Socket::onDataReceived(std::string data) {
@@ -113,7 +116,6 @@ namespace core {
int error = -1;
if((len = ::read(getDescriptor(), buffer, bufferLength)) >= 0) {
// coreutils::Log(coreutils::LOG_DEBUG_4) << "data[" << std::string(buffer, bufferLength) << "]";
onDataReceived(buffer, len);
}
else {
@@ -144,10 +146,8 @@ namespace core {
coreutils::Log(coreutils::LOG_DEBUG_3) << "Writing data to socket " << getDescriptor() << " [" << fifo.front() << "].";
::write(descriptor, fifo.front().c_str(), fifo.front().length());
fifo.pop();
coreutils::Log(coreutils::LOG_DEBUG_4) << "resetSocket from writeSocket.";
ePoll.resetSocket(this);
if(shutDown && !needsToWrite())
delete this;
// if(shutDown && !needsToWrite())
// delete this;
outlock.unlock();
}
}
@@ -157,8 +157,8 @@ namespace core {
outlock.lock();
fifo.emplace(data);
coreutils::Log(coreutils::LOG_DEBUG_4) << "Enabling write on socket " << getDescriptor() << " with " << fifo.size() << " entries to write.";
ePoll.resetSocket(this);
outlock.unlock();
ePoll.resetWrite(this);
return 1;
}
@@ -174,9 +174,8 @@ namespace core {
void Socket::shutdown(std::string text) {
coreutils::Log(coreutils::LOG_DEBUG_2) << "Shutdown requested on socket " << descriptor << " with reason " << text << ".";
shutDown = true;
active = false;
reset = false;
if(!needsToWrite()) {
active = false;
delete this;
}