Major changes to socket scheduling in EPoll.

This commit is contained in:
barant committed 2020-02-29 19:27:58 -08:00
1 parent 790906a6dc
commit a5a51f8aae
512 files changed
+22663 -2121

No files matched your search

+30 -25
View File
@@ -1,11 +1,14 @@
#include "TCPSession.h"
#include "TCPServer.h"
#include "Log.h"
#include "PString.h"
namespace core {
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server) : TCPSocket(ePoll), server(server) {}
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, text), server(server) {}
TCPSession::~TCPSession() {
server.removeFromSessionList(this);
}
@@ -14,43 +17,45 @@ namespace core {
data << "|" << ipAddress.getClientAddressAndPort();
}
void TCPSession::protocol(std::string data = "") {
void TCPSession::protocol(std::stringstream &out, std::string data = "") {
if(data.length() > 0) {
if(!server.commands.processRequest(data, this, out))
server.sessionErrorHandler("Invalid data received.");
send();
}
server.sessionErrorHandler("Invalid data received.", out);
}
else {
onConnected(out);
}
}
void TCPSession::onRegister() {
protocol();
std::stringstream out;
protocol(out);
send(out.str());
}
void TCPSession::onConnected(std::stringstream &out) {}
void TCPSession::onDataReceived(std::string data) {
protocol(data);
std::stringstream out;
protocol(out, data);
send(out.str());
}
void TCPSession::sendToAll() {
for(auto session : server.sessions) {
if(session != this)
session->write(out.str());
}
out.str("");
void TCPSession::sendToAll(std::string data) {
for(auto session : server.sessions)
if(session != this)
session->write(data);
}
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::sendToAll(SessionFilter filter, std::string data) {
for(auto session : server.sessions)
if(filter.test(*session))
if(session != this)
session->write(data);
}
void TCPSession::send() {
write(out.str());
out.str("");
void TCPSession::send(std::string data) {
write(data);
}
}