Added vscode

This commit is contained in:
Brad Arant committed 2020-11-07 17:28:24 -08:00
1 parent 177bc602af
commit f652ba1f34
6 files changed
+165 -136

No files matched your search

+32 -26
View File
@@ -4,23 +4,23 @@
#include "PString.h"
namespace core {
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, text), server(server) {}
TCPSession::~TCPSession() {
server.removeFromSessionList(this);
}
void TCPSession::output(std::stringstream &data) {
data << "|" << ipAddress.getClientAddressAndPort();
}
void TCPSession::protocol(std::string data = "") {
if(!server.commands.processRequest(data, this, out))
if(!server.commands.processRequest(data, this, out))
if(data != "")
server.sessionErrorHandler("Invalid data received.", out);
}
void TCPSession::onRegistered() {
onConnected();
protocol();
@@ -30,17 +30,17 @@ namespace core {
}
void TCPSession::onConnected() {}
void TCPSession::onDataReceived(char *data, int len) {
if(len > 0) {
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize + len);
memcpy(lineBuffer + lineBufferSize, data, len);
lineBufferSize += len;
while(lineBufferSize > 0) {
while(lineBufferSize > 0) {
switch(mode) {
case LINE:
lineLength = strcspn(lineBuffer, "\r\n");
if(lineLength == lineBufferSize)
if(lineLength == lineBufferSize)
break;
onLineReceived(std::string(lineBuffer, lineLength));
if(lineBuffer[lineLength] == '\r')
@@ -48,53 +48,59 @@ namespace core {
if(lineBuffer[lineLength] == '\n')
++lineLength;
lineBufferSize -= lineLength;
if(lineBufferSize > 0)
if(lineBufferSize > 0)
memmove(lineBuffer, lineBuffer + lineLength, lineBufferSize);
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
break;
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
break;
case BLOCK:
if(lineBufferSize >= blockLength) {
if(lineBufferSize >= blockLength) {
onBlockReceived(std::string(lineBuffer, blockLength));
lineBufferSize -= blockLength;
if(lineBufferSize > 0)
if(lineBufferSize > 0)
memmove(lineBuffer, lineBuffer + blockLength, lineBufferSize);
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
lineBuffer = (char *)realloc(lineBuffer, lineBufferSize);
}
break;
}
}
}
}
}
void TCPSession::setMode(core::Mode mode, int blockSize) {
this->mode = mode;
this->blockSize = blockSize;
}
void TCPSession::onLineReceived(std::string line) {
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << line << "]";
protocol(line);
send();
if(term)
shutdown("termination requested");
shutdown("termination requested");
}
void TCPSession::onBlockReceived(std::string block) {
coreutils::Log(coreutils::LOG_DEBUG_3) << "[" << block.length() << "]";
if(term)
shutdown("termination requested");
}
void TCPSession::sendToAll() {
for(auto session : server.sessions)
for(auto session : server.sessions)
if(session != this)
session->write(out.str());
session->write(out.str());
out.str("");
}
void TCPSession::sendToAll(SessionFilter filter) {
for(auto session : server.sessions)
if(filter.test(*session))
for(auto session : server.sessions)
if(filter.test(*session))
if(session != this)
session->write(out.str());
out.str("");
}
void TCPSession::send() {
if(out.tellp() > 0)
write(out.str());
@@ -104,5 +110,5 @@ namespace core {
void TCPSession::terminate() {
term = true;
}
}