Elimination of Service object,
This commit is contained in:
1 parent
a46db126e9
commit
a40f7314a8
440 files changed
+17787
-516
No files matched your search
@@ -0,0 +1,56 @@
|
||||
#include "TCPSession.h"
|
||||
#include "TCPServer.h"
|
||||
#include "Log.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server) : TCPSocket(ePoll), server(server) {}
|
||||
|
||||
TCPSession::~TCPSession() {
|
||||
server.removeFromSessionList(this);
|
||||
}
|
||||
|
||||
void TCPSession::output(std::stringstream &data) {
|
||||
data << "|" << ipAddress.getClientAddressAndPort();
|
||||
}
|
||||
|
||||
void TCPSession::protocol(std::string data = "") {
|
||||
if(data.length() > 0) {
|
||||
if(!server.commands.processRequest(data, this, out))
|
||||
server.sessionErrorHandler("Invalid data received.");
|
||||
send();
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSession::onConnected() {
|
||||
protocol();
|
||||
}
|
||||
|
||||
void TCPSession::onDataReceived(std::string data) {
|
||||
protocol(data);
|
||||
}
|
||||
|
||||
void TCPSession::sendToAll() {
|
||||
for(auto session : server.sessions) {
|
||||
if(session != this)
|
||||
session->write(out.str());
|
||||
}
|
||||
out.str("");
|
||||
}
|
||||
|
||||
void TCPSession::sendToAll(SessionFilter filter) {
|
||||
for(auto session : server.sessions) {
|
||||
if(filter.test(*session)) {
|
||||
if(session != this)
|
||||
session->write(out.str());
|
||||
}
|
||||
}
|
||||
out.str("");
|
||||
}
|
||||
|
||||
void TCPSession::send() {
|
||||
write(out.str());
|
||||
out.str("");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user