Merge branch 'develop' of ssh://barant.com/git/ServerCore into develop

This commit is contained in:
Brad Arant 2021-08-11 21:59:25 -07:00
commit 86bd62221f
33 changed files with 57 additions and 36 deletions

2
.gitignore vendored
View File

@ -6,3 +6,5 @@ Release
libServerCore.a
docs/latex/
docs/html
*/*.ipch
*/mmap_address.bin

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,5 @@
#include "ConsoleSession.h"
#include "TCPServer.h"
#include "Log.h"
namespace core {
@ -50,7 +51,7 @@ namespace core {
case PROCESS:
doCommand(command);
status = command.equals((char *)"exit") ? DONE: PROMPT;
status = command.equals("exit") ? DONE: PROMPT;
protocol(blank);
break;
@ -65,9 +66,9 @@ namespace core {
}
void ConsoleSession::writeLog(std::string data) {
saveCursor();
setCursorLocation(16, 1);
restoreCursor();
// saveCursor();
// setCursorLocation(16, 1);
// restoreCursor();
}
void ConsoleSession::doCommand(coreutils::ZString &request) {

View File

@ -2,11 +2,13 @@
#define __ConsoleSession_h__
#include "TerminalSession.h"
#include "TCPSession.h"
//#include "TCPServer.h"
#include "CommandList.h"
namespace core {
class TCPServer;
///
/// ConsoleSession
///

View File

@ -1,6 +1,7 @@
#include "EPoll.h"
#include "Socket.h"
#include "Exception.h"
#include "ZString.h"
#include "Log.h"
namespace core {
@ -10,7 +11,7 @@ namespace core {
buffer = (char *)malloc(4096);
length = 4096;
}
Socket::~Socket() {
free(buffer);
if(descriptor == -1)
@ -36,11 +37,11 @@ namespace core {
onRegistered();
lock.unlock();
}
int Socket::getDescriptor() {
return descriptor;
}
void Socket::setBufferSize(int length) {
this->length = length;
buffer = (char *)realloc(buffer, length);
@ -50,7 +51,7 @@ namespace core {
int Socket::getBufferSize() {
return length;
}
void Socket::onRegister() {}
void Socket::onRegistered() {}
@ -101,6 +102,8 @@ namespace core {
void Socket::receiveData(coreutils::ZString &buffer) {
coreutils::ZString blank("");
if(buffer.getLength() <= 0)
throw coreutils::Exception("Request to receive data with a zero buffer length.", __FILE__, __LINE__, -1);
@ -113,22 +116,23 @@ namespace core {
}
else {
error = errno;
error = errno;
switch (error) {
switch (error) {
// When a listening socket receives a connection
// request we get one of these.
//
case ENOTCONN:
onDataReceived(std::string(buffer.getData(), 0));
break;
case ECONNRESET:
// When a listening socket receives a connection
// request we get one of these.
//
case ENOTCONN:
onDataReceived(blank);
break;
case ECONNRESET:
break;
default:
default:
throw coreutils::Exception("Error in read of data from socket.", __FILE__, __LINE__, error);
}
}
}
}

View File

@ -31,7 +31,7 @@ namespace core {
/// receiving the EPOLLOUT event then the buffer is written to the socket output.
///
class Socket : public core::Object {
class Socket {
public:

View File

@ -32,8 +32,11 @@ namespace core {
}
TCPSession * TCPServer::accept() {
TCPSession *session = getSocketAccept(ePoll);
session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.addr, &session->ipAddress.addressLength));
try {
TCPSession *session = getSocketAccept(ePoll);
session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.addr, &session->ipAddress.addressLength));
// if(blackList && blackList->contains(session->ipAddress.getClientAddress())) {
// session->shutdown();
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is blacklisted and was denied a connection.";
@ -44,8 +47,16 @@ namespace core {
// Log(LOG_WARN) << "Client at IP address " << session->ipAddress.getClientAddress() << " is not authorized and was denied a connection.";
// return NULL;
// }
coreutils::Log(coreutils::LOG_DEBUG_2) << "Session started on socket " << session->getDescriptor() << ".";
return session;
coreutils::Log(coreutils::LOG_DEBUG_2) << "Session started on socket " << session->getDescriptor() << ".";
return session;
}
catch(coreutils::Exception e) {
coreutils::Log(coreutils::LOG_EXCEPT) << "Major error on session initialization. Error is '" << e.text << "'.";
}
catch(...) {
coreutils::Log(coreutils::LOG_EXCEPT) << "Unnspecified error on session initialization.";
}
return NULL;
}
void TCPServer::removeFromSessionList(TCPSession *session) {

View File

@ -22,8 +22,8 @@ namespace core {
void TCPSession::onRegistered() {
onConnected();
coreutils::ZString nothing("");
protocol(nothing);
coreutils::ZString blank("");
protocol(blank);
send();
if(term)
shutdown("termination requested");
@ -73,13 +73,13 @@ namespace core {
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());

View File

@ -2,11 +2,11 @@
#define __Terminal_h__
#include "includes"
#include "TLSSession.h"
#include "TCPSession.h"
#include "TCPServer.h"
namespace core {
static const int FG_BLACK = 30;
static const int FG_RED = 31;
static const int FG_GREEN = 32;
@ -15,7 +15,7 @@ namespace core {
static const int FG_MAGENTA = 35;
static const int FG_CYAN = 36;
static const int FG_WHITE = 37;
static const int BG_BLACK = 40;
static const int BG_RED = 41;
static const int BG_GREEN = 42;

View File

@ -60,10 +60,10 @@ namespace core {
for(int ix = 0; ix < rc; ++ix) {
++count;
if(((Socket *)events[ix].data.ptr)->eventReceived(events[ix]))
ePoll.resetSocket((Socket *)events[ix].data.ptr);
}
}
}
ePoll.resetSocket((Socket *)events[ix].data.ptr);
}
}
}
coreutils::Log(coreutils::LOG_DEBUG_1) << "Thread ending with thread id " << threadId << ".";
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -31,3 +31,4 @@ echo -n "Building library documentation manual..."
doxygen docs/latex/doxygen.sty >/dev/null 2>/dev/null
echo "OK"
rm *.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.