Many changes to ServerCore
This commit is contained in:
1 parent
6969ef0fbb
commit
d445834af6
83 files changed
+666
-756
No files matched your search
+14
-24
@@ -59,43 +59,33 @@ namespace core {
|
||||
void Socket::onUnregistered() {}
|
||||
|
||||
bool Socket::eventReceived(struct epoll_event event) {
|
||||
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "waiting for lock on socket " << descriptor << ".";
|
||||
|
||||
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();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << ". RDHUP";
|
||||
lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
if(event.events & EPOLLIN) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLIN " << descriptor;
|
||||
receiveData(buffer, length);
|
||||
if(event.events & EPOLLIN) {}
|
||||
receiveData(buffer);
|
||||
}
|
||||
|
||||
if(event.events & EPOLLWRNORM) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLOUT " << descriptor;
|
||||
writeSocket();
|
||||
writeSocket();
|
||||
}
|
||||
|
||||
if(event.events & EPOLLHUP) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLHUP " << descriptor;
|
||||
shutdown();
|
||||
lock.unlock();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << ". HUP";
|
||||
return false;
|
||||
lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "Release lock on socket " << descriptor << " with reset " << reset << ".";
|
||||
|
||||
reset = true;
|
||||
reset = true;
|
||||
return reset;
|
||||
}
|
||||
|
||||
@@ -103,20 +93,20 @@ namespace core {
|
||||
throw coreutils::Exception("Need to override onDataReceived.", __FILE__, __LINE__, -1);
|
||||
}
|
||||
|
||||
void Socket::onDataReceived(char *buffer, int len) {
|
||||
onDataReceived(std::string(buffer, len));
|
||||
void Socket::onDataReceived(coreutils::ZString data) {
|
||||
onDataReceived(std::string(data.getData(), data.getLength()));
|
||||
}
|
||||
|
||||
void Socket::receiveData(char *buffer, int bufferLength) {
|
||||
void Socket::receiveData(coreutils::ZString buffer) {
|
||||
|
||||
if(bufferLength <= 0)
|
||||
if(buffer.getLength() <= 0)
|
||||
throw coreutils::Exception("Request to receive data with a zero buffer length.", __FILE__, __LINE__, -1);
|
||||
|
||||
int len;
|
||||
int error = -1;
|
||||
|
||||
if((len = ::read(getDescriptor(), buffer, bufferLength)) >= 0) {
|
||||
onDataReceived(buffer, len);
|
||||
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
|
||||
onDataReceived(buffer);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -128,7 +118,7 @@ namespace core {
|
||||
// request we get one of these.
|
||||
//
|
||||
case ENOTCONN:
|
||||
onDataReceived(std::string(buffer, 0));
|
||||
onDataReceived(std::string(buffer.getData(), 0));
|
||||
break;
|
||||
|
||||
case ECONNRESET:
|
||||
|
||||
Reference in new issue
Block a user