Updated code
This commit is contained in:
1 parent
20d5c99517
commit
43489e5b3a
26 files changed
+33
-27
No files matched your search
+9
-6
@@ -1,6 +1,7 @@
|
||||
#include "EPoll.h"
|
||||
#include "Socket.h"
|
||||
#include "Exception.h"
|
||||
#include "ZString.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace core {
|
||||
@@ -23,8 +24,8 @@ namespace core {
|
||||
|
||||
void Socket::setDescriptor(int descriptor) {
|
||||
if((descriptor == -1) && (errno == 24)) {
|
||||
shutdown("Too many files open");
|
||||
coreutils::Exception("Too many files open. Refusing connection.");;
|
||||
shutdown("Too many files open");
|
||||
coreutils::Exception("Too many files open. Refusing connection.");
|
||||
}
|
||||
lock.lock();
|
||||
coreutils::Log(coreutils::LOG_DEBUG_3) << "Descriptor set to " << descriptor << " for Socket.";
|
||||
@@ -70,7 +71,8 @@ namespace core {
|
||||
}
|
||||
|
||||
if(event.events & EPOLLIN) {
|
||||
receiveData(buffer);
|
||||
coreutils::ZString receive(buffer, length);
|
||||
receiveData(receive);
|
||||
}
|
||||
|
||||
if(event.events & EPOLLWRNORM) {
|
||||
@@ -93,11 +95,11 @@ namespace core {
|
||||
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) {
|
||||
void Socket::receiveData(coreutils::ZString &buffer) {
|
||||
|
||||
if(buffer.getLength() <= 0)
|
||||
throw coreutils::Exception("Request to receive data with a zero buffer length.", __FILE__, __LINE__, -1);
|
||||
@@ -106,7 +108,8 @@ namespace core {
|
||||
int error = -1;
|
||||
|
||||
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
|
||||
onDataReceived(buffer);
|
||||
coreutils::ZString zbuffer(buffer.getData(), len);
|
||||
onDataReceived(zbuffer);
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
Reference in new issue
Block a user