Create TCPSession2 for outpubound connections.

This commit is contained in:
Brad Arant committed 2022-10-17 20:03:23 -07:00
1 parent 5c87225c6f
commit fd70c79282
129 files changed
+1902 -710

No files matched your search

+16 -19
View File
@@ -6,35 +6,32 @@
namespace core {
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, text), server(server) {}
TCPSession::~TCPSession() {
server.removeFromSessionList(this);
server.subscriptions.removeSessionSubscriptions(*this);
}
void TCPSession::output(std::stringstream &data) {
data << "|" << ipAddress.getClientAddressAndPort();
}
void TCPSession::protocol(coreutils::ZString &data) {
if(data.getLength() != 0) {
if(server.commands.processRequest(data, *this) == 0) {
coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str();
}
}
if(server.commands.processRequest(data, *this) == 0)
coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << getDescriptor() << " [" << data.str() << "]";
}
void TCPSession::onRegistered() {
onConnected();
coreutils::ZString blank("");
protocol(blank);
// coreutils::ZString blank("");
// protocol(blank);
send();
if(term)
shutdown("termination requested");
}
void TCPSession::onConnected() {}
void TCPSession::onDataReceived(coreutils::ZString &data) {
if(data.getLength() > 0) {
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + data.getLength());
@@ -66,32 +63,32 @@ namespace core {
}
}
}
void TCPSession::setBlockSize(int blockSize) {
this->blockSize = blockSize;
}
void TCPSession::onLineReceived(coreutils::ZString &line) {
protocol(line);
send();
if(term)
shutdown("termination requested");
}
void TCPSession::onBlockReceived(coreutils::ZString &block) {
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.getLength() << "]";
if(term)
shutdown("termination requested");
}
void TCPSession::send() {
if(out.tellp() > 0)
write(out.str());
out.str("");
}
void TCPSession::terminate() {
term = true;
}
}