New build.
This commit is contained in:
1 parent
a5a51f8aae
commit
b4ab5fb86a
835 files changed
+26499
-3119
No files matched your search
+26
-22
@@ -5,12 +5,6 @@
|
||||
|
||||
namespace core {
|
||||
|
||||
Socket::Socket(EPoll &ePoll) : ePoll(ePoll) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "BMASocket object created.";
|
||||
buffer = (char *)malloc(4096);
|
||||
length = 4096;
|
||||
}
|
||||
|
||||
Socket::Socket(EPoll &ePoll, std::string text) : ePoll(ePoll), text(text) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "BMASocket object created [" << text << "].";
|
||||
buffer = (char *)malloc(4096);
|
||||
@@ -32,7 +26,7 @@ namespace core {
|
||||
shutdown("Too many files open");
|
||||
coreutils::Exception("Too many files open. Refusing connection.");;
|
||||
}
|
||||
socketLock.lock();
|
||||
lock.lock();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "Descriptor set to " << descriptor << " for Socket.";
|
||||
if(descriptor < 3)
|
||||
throw coreutils::Exception("Descriptor out of range", __FILE__, __LINE__);
|
||||
@@ -40,7 +34,7 @@ namespace core {
|
||||
onRegister();
|
||||
ePoll.registerSocket(this);
|
||||
onRegistered();
|
||||
socketLock.unlock();
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
int Socket::getDescriptor() {
|
||||
@@ -48,26 +42,33 @@ namespace core {
|
||||
}
|
||||
|
||||
void Socket::setBufferSize(int length) {
|
||||
buffer = (char *)realloc(buffer, length);
|
||||
this->length = length;
|
||||
buffer = (char *)realloc(buffer, length);
|
||||
}
|
||||
|
||||
|
||||
int Socket::getBufferSize() {
|
||||
return length;
|
||||
}
|
||||
|
||||
void Socket::onRegister() {}
|
||||
|
||||
void Socket::onRegistered() {}
|
||||
|
||||
void Socket::onUnregister() {}
|
||||
|
||||
void Socket::onUnregistered() {}
|
||||
|
||||
bool Socket::eventReceived(struct epoll_event event) {
|
||||
bool Socket::eventReceived(struct epoll_event event, int threadId) {
|
||||
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "eventReceived on " << descriptor << "; shutDown = " << shutDown << "; active = " << active << ";";
|
||||
|
||||
socketLock.lock();
|
||||
lock.lock();
|
||||
|
||||
if(event.events & EPOLLRDHUP) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLRDHUP " << descriptor;
|
||||
readHangup = true;
|
||||
shutdown("hangup received");
|
||||
lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -85,11 +86,12 @@ namespace core {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "start EPOLLHUP " << descriptor;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "end shutting down" << descriptor;
|
||||
shutdown();
|
||||
lock.unlock();
|
||||
return false;
|
||||
}
|
||||
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "end with active = " << active << " on socket " << descriptor;
|
||||
socketLock.unlock();
|
||||
lock.unlock();
|
||||
|
||||
return active;
|
||||
}
|
||||
@@ -110,8 +112,10 @@ namespace core {
|
||||
int len;
|
||||
int error = -1;
|
||||
|
||||
if((len = ::read(getDescriptor(), buffer, bufferLength)) >= 0)
|
||||
onDataReceived(buffer, len);
|
||||
if((len = ::read(getDescriptor(), buffer, bufferLength)) >= 0) {
|
||||
// coreutils::Log(coreutils::LOG_DEBUG_4) << "data[" << std::string(buffer, bufferLength) << "]";
|
||||
onDataReceived(buffer, len);
|
||||
}
|
||||
else {
|
||||
|
||||
error = errno;
|
||||
@@ -138,27 +142,27 @@ namespace core {
|
||||
if(shutDown)
|
||||
return;
|
||||
|
||||
lock.lock();
|
||||
if(fifo.size() > 0) {
|
||||
outlock.lock();
|
||||
::write(descriptor, fifo.front().c_str(), fifo.front().length());
|
||||
fifo.pop();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_4) << "reseSocket from writeSocket.";
|
||||
coreutils::Log(coreutils::LOG_DEBUG_4) << "resetSocket from writeSocket.";
|
||||
if(active)
|
||||
ePoll.resetSocket(this);
|
||||
outlock.unlock();
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
int Socket::write(std::string data) {
|
||||
if(!active)
|
||||
return -1;
|
||||
|
||||
lock.lock();
|
||||
return -1;
|
||||
|
||||
outlock.lock();
|
||||
fifo.emplace(data);
|
||||
coreutils::Log(coreutils::LOG_DEBUG_4) << "resetSocket from write. active is " << active;
|
||||
if(active)
|
||||
ePoll.resetSocket(this);
|
||||
lock.unlock();
|
||||
outlock.unlock();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user