Some work - trying to catch up to where I was.
This commit is contained in:
1 parent
96e73d6341
commit
e0c0e2c07e
6 files changed
+45
-47
No files matched your search
+32
-37
@@ -68,47 +68,47 @@ namespace core
|
||||
void Socket::onUnregistered() {}
|
||||
|
||||
bool Socket::eventReceived(struct epoll_event event, long long eventId) {
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process beginning for socket " << getDescriptor();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process beginning for socket " << getDescriptor();
|
||||
if(inHandler)
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true.";
|
||||
inHandler = true;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true.";
|
||||
inHandler = true;
|
||||
if(event.events & EPOLLRDHUP) {
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLRDHUP";
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLRDHUP";
|
||||
readHangup = true;
|
||||
shutdown("hangup received");
|
||||
}
|
||||
if(event.events & EPOLLIN) {
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLIN";
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLIN";
|
||||
coreutils::ZString zbuffer(buffer, length);
|
||||
lock.lock();
|
||||
receiveData(zbuffer);
|
||||
if(!shutDown) {
|
||||
inHandler = false;
|
||||
lock.unlock();
|
||||
lock.unlock();
|
||||
resetSocket();
|
||||
}
|
||||
}
|
||||
if(event.events & EPOLLWRNORM) {
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLWRNORM";
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLWRNORM";
|
||||
writeSocket();
|
||||
inHandler = false;
|
||||
resetSocket();
|
||||
resetSocket();
|
||||
}
|
||||
inHandler = false;
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process ending for socket " << getDescriptor();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process ending for socket " << getDescriptor();
|
||||
return !shutDown;
|
||||
}
|
||||
|
||||
void Socket::onDataReceived(std::string data)
|
||||
{
|
||||
|
||||
void Socket::connectionRequest() {}
|
||||
|
||||
void Socket::onDataReceived(std::string data) {
|
||||
throw coreutils::Exception("Need to override onDataReceived.", __FILE__, __LINE__, -1);
|
||||
}
|
||||
|
||||
void Socket::onDataReceived(coreutils::ZString &data)
|
||||
{
|
||||
|
||||
void Socket::onDataReceived(coreutils::ZString &data) {
|
||||
onDataReceived(std::string(data.getData(), data.getLength()));
|
||||
}
|
||||
|
||||
|
||||
void Socket::receiveData(coreutils::ZString &buffer) {
|
||||
coreutils::ZString blank("");
|
||||
if(buffer.getLength() <= 0)
|
||||
@@ -117,36 +117,31 @@ namespace core
|
||||
int error = -1;
|
||||
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
|
||||
coreutils::ZString zbuffer(buffer.getData(), len);
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << zbuffer;
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << zbuffer;
|
||||
onDataReceived(zbuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
error = errno;
|
||||
|
||||
switch (error)
|
||||
{
|
||||
|
||||
} else {
|
||||
error = errno;
|
||||
switch (error) {
|
||||
|
||||
// When a listening socket receives a connection
|
||||
// request we get one of these.
|
||||
//
|
||||
case ENOTCONN:
|
||||
onDataReceived(blank);
|
||||
// request we get one of these.
|
||||
|
||||
case ENOTCONN:
|
||||
connectionRequest();
|
||||
break;
|
||||
|
||||
case ECONNRESET:
|
||||
|
||||
case ECONNRESET:
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
default:
|
||||
throw coreutils::Exception("Error in read of data from socket.", __FILE__, __LINE__, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Socket::writeSocket() {
|
||||
outlock.lock();
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "writing data to socket " << getDescriptor();
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "writing data to socket " << getDescriptor();
|
||||
if(fifo.size() > 0) {
|
||||
if(!shutDown)
|
||||
int rc = ::write(descriptor, fifo.front().c_str(), fifo.front().length());
|
||||
@@ -154,7 +149,7 @@ namespace core
|
||||
}
|
||||
outlock.unlock();
|
||||
}
|
||||
|
||||
|
||||
int Socket::write(std::string data) {
|
||||
outlock.lock();
|
||||
fifo.emplace(data);
|
||||
|
||||
Reference in new issue
Block a user