Initial repository 1.0.0
This commit is contained in:
commit
d8b1275884
27
Command.cpp
Normal file
27
Command.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "Command.h"
|
||||||
|
#include "Session.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
void Command::output(Session *session) {}
|
||||||
|
|
||||||
|
bool Command::check(std::string request) {
|
||||||
|
if(request != "") {
|
||||||
|
if(name.length() > 0) {
|
||||||
|
size_t start = request.find_first_not_of(" ");
|
||||||
|
if(name == request.substr(start, name.length()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command::setName(std::string name) {
|
||||||
|
this->name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Command::getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
Command.h
Normal file
79
Command.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#ifndef __Command_h__
|
||||||
|
#define __Command_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Object.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class Session;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Command
|
||||||
|
///
|
||||||
|
/// Use the Command object in combination with a CommandList object to maintain
|
||||||
|
/// a list of functions that can be invoked as a result of processing a request.
|
||||||
|
///
|
||||||
|
|
||||||
|
class Command : public Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Implement check method to provide a special check rule upon the request to see
|
||||||
|
/// if the command should be processed.
|
||||||
|
///
|
||||||
|
/// The default rule is to verify that the first token in the request string matches
|
||||||
|
/// the name given on the registration of the command to the CommandList. This can
|
||||||
|
/// be overridden by implementing the check() method to perform the test and return
|
||||||
|
/// the condition of the command.
|
||||||
|
///
|
||||||
|
/// @param request The request passed to the parser to check the rule.
|
||||||
|
/// @return Return true to execute the command. Returning false will cause no action
|
||||||
|
/// on this command.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual bool check(std::string request);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// This method is used to implement the functionality of the requested command.
|
||||||
|
/// This pure virtual function must be implemented in your inheriting object.
|
||||||
|
///
|
||||||
|
/// @param request The request that was entered by the user to invoke this command.
|
||||||
|
/// @param session Specify the requesting session so that the execution of the
|
||||||
|
/// command process can return its output to the session.
|
||||||
|
/// @return Returns 0 if execution of the command was successful. Otherwise returns
|
||||||
|
/// a non-zero value indicating an error condition.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual int processCommand(std::string request, Session *session) = 0;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Specify the output that will occur to the specified session.
|
||||||
|
///
|
||||||
|
/// @param session The session that will receive the output.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void output(Session *session);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Set the name of this command used in default rule checking during request parsing.
|
||||||
|
/// NOTE: You do not need to call this under normal conditions as adding a Command
|
||||||
|
/// to a CommandList using the add() method contains a parameter to pass the name
|
||||||
|
/// of the Command.
|
||||||
|
///
|
||||||
|
/// @param name Specify the name of this command for default parsing.
|
||||||
|
///
|
||||||
|
|
||||||
|
void setName(std::string name);
|
||||||
|
|
||||||
|
std::string getName();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
41
CommandList.cpp
Normal file
41
CommandList.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "CommandList.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
CommandList::CommandList() {}
|
||||||
|
|
||||||
|
CommandList::~CommandList() {}
|
||||||
|
|
||||||
|
void CommandList::add(Command &command, std::string name) {
|
||||||
|
command.setName(name);
|
||||||
|
commands.push_back(&command);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CommandList::remove(Command &command) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommandList::processRequest(std::string request, Session *session) {
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
for(auto *command : commands) {
|
||||||
|
if(command->check(request)) {
|
||||||
|
command->processCommand(request, session);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CommandList::processCommand(std::string request, Session *session) {
|
||||||
|
for(Command *command : commands)
|
||||||
|
session->out << command->getName() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
30
CommandList.h
Normal file
30
CommandList.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef __CommandList_h__
|
||||||
|
#define __CommandList_h__
|
||||||
|
|
||||||
|
#include "Session.h"
|
||||||
|
#include "Command.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class CommandList : public Command {
|
||||||
|
|
||||||
|
public:
|
||||||
|
CommandList();
|
||||||
|
~CommandList();
|
||||||
|
|
||||||
|
void add(Command &command, std::string name = "");
|
||||||
|
|
||||||
|
void remove(Command &command);
|
||||||
|
|
||||||
|
bool processRequest(std::string request, Session *session);
|
||||||
|
|
||||||
|
int processCommand(std::string request, Session *session) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<Command *> commands;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
28
ConsoleServer.cpp
Normal file
28
ConsoleServer.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "ConsoleServer.h"
|
||||||
|
#include "ConsoleSession.h"
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
ConsoleServer::ConsoleServer(EPoll &ePoll, std::string url, short int port)
|
||||||
|
: TCPServerSocket(ePoll, url, port) {
|
||||||
|
Log(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleServer::~ConsoleServer() {}
|
||||||
|
|
||||||
|
void ConsoleServer::sendToConnectedConsoles(std::string out) {
|
||||||
|
for(auto *session : sessions)
|
||||||
|
((ConsoleSession *)session)->writeLog(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
Session * ConsoleServer::getSocketAccept() {
|
||||||
|
return new ConsoleSession(ePoll, *this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleServer::output(Session *session) {
|
||||||
|
session->out << "|" << session->ipAddress.getClientAddressAndPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
ConsoleServer.h
Normal file
47
ConsoleServer.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef __ConsoleServer_h__
|
||||||
|
#define __ConsoleServer_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "TCPServerSocket.h"
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Session.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class TCPSocket;
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
|
class ConsoleServer : public TCPServerSocket {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
ConsoleServer(EPoll &ePoll, std::string url, short int port);
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
~ConsoleServer();
|
||||||
|
|
||||||
|
void sendToConnectedConsoles(std::string out);
|
||||||
|
|
||||||
|
void output(Session *session) override; ///<Output the consoles array to the console.
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Session * getSocketAccept() override;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
114
ConsoleSession.cpp
Normal file
114
ConsoleSession.cpp
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
#include "ConsoleSession.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
ConsoleSession::ConsoleSession(EPoll &ePoll, ConsoleServer &server) : TerminalSession(ePoll, server) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ConsoleSession::~ConsoleSession() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleSession::output(std::stringstream &out) {
|
||||||
|
// socket->output(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleSession::protocol(std::string data = "") {
|
||||||
|
|
||||||
|
switch (status) {
|
||||||
|
|
||||||
|
case WELCOME:
|
||||||
|
setBackColor(BG_BLACK);
|
||||||
|
clear();
|
||||||
|
setCursorLocation(1, 1);
|
||||||
|
setBackColor(BG_BLUE);
|
||||||
|
clearEOL();
|
||||||
|
out << "ConsoleSession";
|
||||||
|
setCursorLocation(2, 1);
|
||||||
|
setBackColor(BG_BLACK);
|
||||||
|
status = LOGIN;
|
||||||
|
protocol();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOGIN:
|
||||||
|
setCursorLocation(3, 3);
|
||||||
|
out << "Enter User Profile: ";
|
||||||
|
send();
|
||||||
|
status = WAIT_USER_PROFILE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WAIT_USER_PROFILE:
|
||||||
|
status = PASSWORD;
|
||||||
|
protocol();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PASSWORD:
|
||||||
|
setCursorLocation(4, 7);
|
||||||
|
out << "Enter Password: ";
|
||||||
|
send();
|
||||||
|
status = WAIT_PASSWORD;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WAIT_PASSWORD:
|
||||||
|
setBackColor(BG_BLACK);
|
||||||
|
clear();
|
||||||
|
setCursorLocation(1, 1);
|
||||||
|
setBackColor(BG_BLUE);
|
||||||
|
clearEOL();
|
||||||
|
out << "ConsoleSession";
|
||||||
|
setCursorLocation(2, 1);
|
||||||
|
setBackColor(BG_BLACK);
|
||||||
|
scrollArea(2, 16);
|
||||||
|
status = PROMPT;
|
||||||
|
protocol();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROMPT:
|
||||||
|
Log(LOG_DEBUG_1) << "Lines is " << getLines() << ".";
|
||||||
|
setCursorLocation(17, 1);
|
||||||
|
clearEOL();
|
||||||
|
out << ("--> ");
|
||||||
|
send();
|
||||||
|
status = INPUT;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case INPUT:
|
||||||
|
command = std::string(data);
|
||||||
|
command.erase(command.find_last_not_of("\r\n\t") + 1);
|
||||||
|
status = PROCESS;
|
||||||
|
protocol();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PROCESS:
|
||||||
|
doCommand(command);
|
||||||
|
status = (command == "exit")? DONE: PROMPT;
|
||||||
|
protocol();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DONE:
|
||||||
|
out << "Done." << std::endl;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
out << "Unrecognized status code: ERROR.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleSession::writeLog(std::string data) {
|
||||||
|
saveCursor();
|
||||||
|
setCursorLocation(16, 1);
|
||||||
|
out << data;
|
||||||
|
restoreCursor();
|
||||||
|
send();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConsoleSession::doCommand(std::string request) {
|
||||||
|
saveCursor();
|
||||||
|
setCursorLocation(16, 1);
|
||||||
|
out << "--> " << request << std::endl;
|
||||||
|
server.commands.processRequest(request, this);
|
||||||
|
restoreCursor();
|
||||||
|
send();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
ConsoleSession.h
Normal file
41
ConsoleSession.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#ifndef __ConsoleSession_h__
|
||||||
|
#define __ConsoleSession_h__
|
||||||
|
|
||||||
|
#include "TerminalSession.h"
|
||||||
|
#include "Session.h"
|
||||||
|
#include "ConsoleServer.h"
|
||||||
|
#include "CommandList.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// ConsoleSession
|
||||||
|
///
|
||||||
|
/// Extends the session parameters for this TCPSocket derived object.
|
||||||
|
/// Extend the protocol() method in order to define the behavior and
|
||||||
|
/// protocol interaction for this socket which is a console session.
|
||||||
|
///
|
||||||
|
|
||||||
|
class ConsoleSession : public TerminalSession {
|
||||||
|
|
||||||
|
public:
|
||||||
|
ConsoleSession(EPoll &ePoll, ConsoleServer &server);
|
||||||
|
~ConsoleSession();
|
||||||
|
|
||||||
|
virtual void output(std::stringstream &out);
|
||||||
|
void writeLog(std::string data);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void protocol(std::string data) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum Status {WELCOME, LOGIN, WAIT_USER_PROFILE, PASSWORD, WAIT_PASSWORD, PROMPT, INPUT, PROCESS, DONE};
|
||||||
|
Status status = WELCOME;
|
||||||
|
void doCommand(std::string request);
|
||||||
|
std::string command;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
BIN
Debug/Command.cpp.o
Normal file
BIN
Debug/Command.cpp.o
Normal file
Binary file not shown.
18
Debug/Command.cpp.o.d
Normal file
18
Debug/Command.cpp.o.d
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
Debug/Command.cpp.o: Command.cpp Command.h includes Object.h Session.h \
|
||||||
|
TCPSocket.h Socket.h IPAddress.h SessionFilter.h
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
BIN
Debug/CommandList.cpp.o
Normal file
BIN
Debug/CommandList.cpp.o
Normal file
Binary file not shown.
21
Debug/CommandList.cpp.o.d
Normal file
21
Debug/CommandList.cpp.o.d
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
Debug/CommandList.cpp.o: CommandList.cpp CommandList.h Session.h \
|
||||||
|
TCPSocket.h includes Socket.h Object.h IPAddress.h SessionFilter.h \
|
||||||
|
Command.h
|
||||||
|
|
||||||
|
CommandList.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
Command.h:
|
BIN
Debug/ConsoleServer.cpp.o
Normal file
BIN
Debug/ConsoleServer.cpp.o
Normal file
Binary file not shown.
38
Debug/ConsoleServer.cpp.o.d
Normal file
38
Debug/ConsoleServer.cpp.o.d
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Debug/ConsoleServer.cpp.o: ConsoleServer.cpp ConsoleServer.h includes \
|
||||||
|
TCPServerSocket.h Socket.h Object.h TCPSocket.h IPAddress.h Command.h \
|
||||||
|
CommandList.h Session.h SessionFilter.h EPoll.h Log.h File.h Thread.h \
|
||||||
|
ConsoleSession.h TerminalSession.h
|
||||||
|
|
||||||
|
ConsoleServer.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
TCPServerSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
CommandList.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
ConsoleSession.h:
|
||||||
|
|
||||||
|
TerminalSession.h:
|
BIN
Debug/ConsoleSession.cpp.o
Normal file
BIN
Debug/ConsoleSession.cpp.o
Normal file
Binary file not shown.
38
Debug/ConsoleSession.cpp.o.d
Normal file
38
Debug/ConsoleSession.cpp.o.d
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Debug/ConsoleSession.cpp.o: ConsoleSession.cpp ConsoleSession.h \
|
||||||
|
TerminalSession.h includes Session.h TCPSocket.h Socket.h Object.h \
|
||||||
|
IPAddress.h SessionFilter.h ConsoleServer.h TCPServerSocket.h Command.h \
|
||||||
|
CommandList.h EPoll.h Log.h File.h Thread.h
|
||||||
|
|
||||||
|
ConsoleSession.h:
|
||||||
|
|
||||||
|
TerminalSession.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
ConsoleServer.h:
|
||||||
|
|
||||||
|
TCPServerSocket.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
CommandList.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
BIN
Debug/EPoll.cpp.o
Normal file
BIN
Debug/EPoll.cpp.o
Normal file
Binary file not shown.
29
Debug/EPoll.cpp.o.d
Normal file
29
Debug/EPoll.cpp.o.d
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Debug/EPoll.cpp.o: EPoll.cpp Thread.h includes Log.h File.h Object.h \
|
||||||
|
Session.h TCPSocket.h Socket.h IPAddress.h SessionFilter.h EPoll.h \
|
||||||
|
Command.h Exception.h
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
Exception.h:
|
BIN
Debug/Exception.cpp.o
Normal file
BIN
Debug/Exception.cpp.o
Normal file
Binary file not shown.
12
Debug/Exception.cpp.o.d
Normal file
12
Debug/Exception.cpp.o.d
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Debug/Exception.cpp.o: Exception.cpp Exception.h includes Log.h File.h \
|
||||||
|
Object.h
|
||||||
|
|
||||||
|
Exception.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Object.h:
|
BIN
Debug/File.cpp.o
Normal file
BIN
Debug/File.cpp.o
Normal file
Binary file not shown.
7
Debug/File.cpp.o.d
Normal file
7
Debug/File.cpp.o.d
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Debug/File.cpp.o: File.cpp File.h includes Exception.h
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Exception.h:
|
BIN
Debug/Header.cpp.o
Normal file
BIN
Debug/Header.cpp.o
Normal file
Binary file not shown.
11
Debug/Header.cpp.o.d
Normal file
11
Debug/Header.cpp.o.d
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
Debug/Header.cpp.o: Header.cpp Header.h includes Object.h Log.h File.h
|
||||||
|
|
||||||
|
Header.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
BIN
Debug/IPAddress.cpp.o
Normal file
BIN
Debug/IPAddress.cpp.o
Normal file
Binary file not shown.
7
Debug/IPAddress.cpp.o.d
Normal file
7
Debug/IPAddress.cpp.o.d
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Debug/IPAddress.cpp.o: IPAddress.cpp IPAddress.h includes Object.h
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
BIN
Debug/Log.cpp.o
Normal file
BIN
Debug/Log.cpp.o
Normal file
Binary file not shown.
38
Debug/Log.cpp.o.d
Normal file
38
Debug/Log.cpp.o.d
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Debug/Log.cpp.o: Log.cpp ConsoleSession.h TerminalSession.h includes \
|
||||||
|
Session.h TCPSocket.h Socket.h Object.h IPAddress.h SessionFilter.h \
|
||||||
|
ConsoleServer.h TCPServerSocket.h Command.h CommandList.h EPoll.h Log.h \
|
||||||
|
File.h Thread.h
|
||||||
|
|
||||||
|
ConsoleSession.h:
|
||||||
|
|
||||||
|
TerminalSession.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
ConsoleServer.h:
|
||||||
|
|
||||||
|
TCPServerSocket.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
CommandList.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
BIN
Debug/Response.cpp.o
Normal file
BIN
Debug/Response.cpp.o
Normal file
Binary file not shown.
12
Debug/Response.cpp.o.d
Normal file
12
Debug/Response.cpp.o.d
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Debug/Response.cpp.o: Response.cpp Response.h includes Object.h Log.h \
|
||||||
|
File.h
|
||||||
|
|
||||||
|
Response.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
BIN
Debug/Session.cpp.o
Normal file
BIN
Debug/Session.cpp.o
Normal file
Binary file not shown.
27
Debug/Session.cpp.o.d
Normal file
27
Debug/Session.cpp.o.d
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
Debug/Session.cpp.o: Session.cpp Session.h TCPSocket.h includes Socket.h \
|
||||||
|
Object.h IPAddress.h SessionFilter.h Log.h File.h TCPServerSocket.h \
|
||||||
|
Command.h CommandList.h
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
TCPServerSocket.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
CommandList.h:
|
BIN
Debug/Socket.cpp.o
Normal file
BIN
Debug/Socket.cpp.o
Normal file
Binary file not shown.
29
Debug/Socket.cpp.o.d
Normal file
29
Debug/Socket.cpp.o.d
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Debug/Socket.cpp.o: Socket.cpp EPoll.h Log.h includes File.h Object.h \
|
||||||
|
Socket.h Thread.h Session.h TCPSocket.h IPAddress.h SessionFilter.h \
|
||||||
|
Command.h Exception.h
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
Exception.h:
|
BIN
Debug/TCPServerSocket.cpp.o
Normal file
BIN
Debug/TCPServerSocket.cpp.o
Normal file
Binary file not shown.
34
Debug/TCPServerSocket.cpp.o.d
Normal file
34
Debug/TCPServerSocket.cpp.o.d
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
Debug/TCPServerSocket.cpp.o: TCPServerSocket.cpp TCPServerSocket.h \
|
||||||
|
Socket.h includes Object.h TCPSocket.h IPAddress.h Command.h \
|
||||||
|
CommandList.h Session.h SessionFilter.h EPoll.h Log.h File.h Thread.h \
|
||||||
|
Exception.h
|
||||||
|
|
||||||
|
TCPServerSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
CommandList.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
Exception.h:
|
BIN
Debug/TCPSocket.cpp.o
Normal file
BIN
Debug/TCPSocket.cpp.o
Normal file
Binary file not shown.
29
Debug/TCPSocket.cpp.o.d
Normal file
29
Debug/TCPSocket.cpp.o.d
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Debug/TCPSocket.cpp.o: TCPSocket.cpp TCPSocket.h includes Socket.h \
|
||||||
|
Object.h IPAddress.h EPoll.h Log.h File.h Thread.h Session.h \
|
||||||
|
SessionFilter.h Command.h Exception.h
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
Exception.h:
|
BIN
Debug/TLSServerSocket.cpp.o
Normal file
BIN
Debug/TLSServerSocket.cpp.o
Normal file
Binary file not shown.
38
Debug/TLSServerSocket.cpp.o.d
Normal file
38
Debug/TLSServerSocket.cpp.o.d
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Debug/TLSServerSocket.cpp.o: TLSServerSocket.cpp TLSServerSocket.h \
|
||||||
|
Socket.h includes Object.h TCPServerSocket.h TCPSocket.h IPAddress.h \
|
||||||
|
Command.h CommandList.h Session.h SessionFilter.h TLSSession.h EPoll.h \
|
||||||
|
Log.h File.h Thread.h Exception.h
|
||||||
|
|
||||||
|
TLSServerSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
TCPServerSocket.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
CommandList.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
TLSSession.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
Exception.h:
|
BIN
Debug/TLSSession.cpp.o
Normal file
BIN
Debug/TLSSession.cpp.o
Normal file
Binary file not shown.
38
Debug/TLSSession.cpp.o.d
Normal file
38
Debug/TLSSession.cpp.o.d
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Debug/TLSSession.cpp.o: TLSSession.cpp TLSSession.h includes Session.h \
|
||||||
|
TCPSocket.h Socket.h Object.h IPAddress.h SessionFilter.h \
|
||||||
|
TLSServerSocket.h TCPServerSocket.h Command.h CommandList.h EPoll.h \
|
||||||
|
Log.h File.h Thread.h Exception.h
|
||||||
|
|
||||||
|
TLSSession.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
TLSServerSocket.h:
|
||||||
|
|
||||||
|
TCPServerSocket.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
CommandList.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
Exception.h:
|
BIN
Debug/TerminalSession.cpp.o
Normal file
BIN
Debug/TerminalSession.cpp.o
Normal file
Binary file not shown.
19
Debug/TerminalSession.cpp.o.d
Normal file
19
Debug/TerminalSession.cpp.o.d
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
Debug/TerminalSession.cpp.o: TerminalSession.cpp TerminalSession.h \
|
||||||
|
includes Session.h TCPSocket.h Socket.h Object.h IPAddress.h \
|
||||||
|
SessionFilter.h
|
||||||
|
|
||||||
|
TerminalSession.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
BIN
Debug/Thread.cpp.o
Normal file
BIN
Debug/Thread.cpp.o
Normal file
Binary file not shown.
27
Debug/Thread.cpp.o.d
Normal file
27
Debug/Thread.cpp.o.d
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
Debug/Thread.cpp.o: Thread.cpp Thread.h includes Log.h File.h Object.h \
|
||||||
|
Session.h TCPSocket.h Socket.h IPAddress.h SessionFilter.h EPoll.h \
|
||||||
|
Command.h
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Command.h:
|
BIN
Debug/Timer.cpp.o
Normal file
BIN
Debug/Timer.cpp.o
Normal file
Binary file not shown.
29
Debug/Timer.cpp.o.d
Normal file
29
Debug/Timer.cpp.o.d
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
Debug/Timer.cpp.o: Timer.cpp Timer.h Socket.h includes Object.h EPoll.h \
|
||||||
|
Log.h File.h Thread.h Session.h TCPSocket.h IPAddress.h SessionFilter.h \
|
||||||
|
Command.h
|
||||||
|
|
||||||
|
Timer.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
Command.h:
|
BIN
Debug/UDPServerSocket.cpp.o
Normal file
BIN
Debug/UDPServerSocket.cpp.o
Normal file
Binary file not shown.
31
Debug/UDPServerSocket.cpp.o.d
Normal file
31
Debug/UDPServerSocket.cpp.o.d
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
Debug/UDPServerSocket.cpp.o: UDPServerSocket.cpp UDPServerSocket.h \
|
||||||
|
Socket.h includes Object.h UDPSocket.h Session.h TCPSocket.h IPAddress.h \
|
||||||
|
SessionFilter.h Command.h EPoll.h Log.h File.h Thread.h
|
||||||
|
|
||||||
|
UDPServerSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
UDPSocket.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
||||||
|
|
||||||
|
Command.h:
|
||||||
|
|
||||||
|
EPoll.h:
|
||||||
|
|
||||||
|
Log.h:
|
||||||
|
|
||||||
|
File.h:
|
||||||
|
|
||||||
|
Thread.h:
|
BIN
Debug/UDPSocket.cpp.o
Normal file
BIN
Debug/UDPSocket.cpp.o
Normal file
Binary file not shown.
18
Debug/UDPSocket.cpp.o.d
Normal file
18
Debug/UDPSocket.cpp.o.d
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
Debug/UDPSocket.cpp.o: UDPSocket.cpp UDPSocket.h Socket.h includes \
|
||||||
|
Object.h Session.h TCPSocket.h IPAddress.h SessionFilter.h
|
||||||
|
|
||||||
|
UDPSocket.h:
|
||||||
|
|
||||||
|
Socket.h:
|
||||||
|
|
||||||
|
includes:
|
||||||
|
|
||||||
|
Object.h:
|
||||||
|
|
||||||
|
Session.h:
|
||||||
|
|
||||||
|
TCPSocket.h:
|
||||||
|
|
||||||
|
IPAddress.h:
|
||||||
|
|
||||||
|
SessionFilter.h:
|
BIN
Debug/libServerCore.a
Normal file
BIN
Debug/libServerCore.a
Normal file
Binary file not shown.
127
EPoll.cpp
Normal file
127
EPoll.cpp
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
#include "Thread.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
#include "Session.h"
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
EPoll::EPoll() : Command() {
|
||||||
|
|
||||||
|
Log(LOG_DEBUG_2) << "EPoll object being constructed.";
|
||||||
|
|
||||||
|
maxSockets = 1000;
|
||||||
|
epfd = epoll_create1(0);
|
||||||
|
terminateThreads = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EPoll::~EPoll() {
|
||||||
|
Log(LOG_DEBUG_2) << "BMAEPoll destructed.";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EPoll::start(int numberOfThreads, int maxSockets) {
|
||||||
|
|
||||||
|
Log(LOG_DEBUG_2) << "Starting epoll event processing.";
|
||||||
|
|
||||||
|
this->numberOfThreads = numberOfThreads;
|
||||||
|
|
||||||
|
Log(LOG_DEBUG_3) << "Number of threads starting is " << numberOfThreads << ".";
|
||||||
|
Log(LOG_DEBUG_3) << "Maximum connections is " << maxSockets << ".";
|
||||||
|
|
||||||
|
// TODO: Set the number of maximum open files to the maxSockets value.
|
||||||
|
//
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// Create thread objects into vector for number of threads requested.
|
||||||
|
// Hand all the threads a pointer to the EPoll object so they can run
|
||||||
|
// the socket handlers.
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
for(int ix = 0; ix < numberOfThreads; ++ix)
|
||||||
|
threads.emplace_back(*this);
|
||||||
|
|
||||||
|
for(int ix = 0; ix < numberOfThreads; ++ix)
|
||||||
|
threads[ix].start();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EPoll::stop() {
|
||||||
|
|
||||||
|
terminateThreads = true;
|
||||||
|
|
||||||
|
//--------------------------------------------------------
|
||||||
|
// Kill and join all the threads that have been started.
|
||||||
|
//--------------------------------------------------------
|
||||||
|
|
||||||
|
for(int ix = 0; ix < numberOfThreads; ++ix)
|
||||||
|
threads[ix].join();
|
||||||
|
|
||||||
|
//--------------------------
|
||||||
|
// Close the epoll socket.
|
||||||
|
//--------------------------
|
||||||
|
|
||||||
|
close(epfd);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EPoll::isStopping() {
|
||||||
|
return terminateThreads;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EPoll::registerSocket(Socket *socket /**< The Socket to register.*/) {
|
||||||
|
lock.lock();
|
||||||
|
std::map<int, Socket *>::iterator temp = sockets.find(socket->getDescriptor());
|
||||||
|
if(temp != sockets.end())
|
||||||
|
throw Exception("Attempt to register socket that is already registered.");
|
||||||
|
Log(LOG_DEBUG_3) << "Registering socket " << socket->getDescriptor() << ".";
|
||||||
|
sockets.insert(std::pair<int, Socket *>(socket->getDescriptor(), socket));
|
||||||
|
lock.unlock();
|
||||||
|
socket->enable(true);
|
||||||
|
socket->onRegistered();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EPoll::unregisterSocket(Socket *socket /**< The Socket to unregister. */) {
|
||||||
|
lock.lock();
|
||||||
|
socket->enable(false);
|
||||||
|
Log(LOG_DEBUG_3) << "Unregistering socket " << socket->getDescriptor() << ".";
|
||||||
|
std::map<int, Socket *>::iterator temp = sockets.find(socket->getDescriptor());
|
||||||
|
if(temp == sockets.end())
|
||||||
|
throw Exception("Attempt to unregister socket that is not registered.");
|
||||||
|
sockets.erase(temp);
|
||||||
|
lock.unlock();
|
||||||
|
socket->onUnregistered();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EPoll::eventReceived(struct epoll_event event) {
|
||||||
|
lock.lock();
|
||||||
|
std::map<int, Socket *>::iterator socket = sockets.find(event.data.fd);
|
||||||
|
lock.unlock();
|
||||||
|
if(socket != sockets.end()) {
|
||||||
|
(socket->second)->eventReceived(event);
|
||||||
|
} else {
|
||||||
|
Log(LOG_WARN) << "System problem. Reference to socket " << event.data.fd << " that has no object.";
|
||||||
|
throw Exception("System problem occurred.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int EPoll::getDescriptor() {
|
||||||
|
return epfd;
|
||||||
|
}
|
||||||
|
|
||||||
|
int EPoll::processCommand(std::string command, Session *session) {
|
||||||
|
|
||||||
|
int sequence = 0;
|
||||||
|
|
||||||
|
for(auto threadx : threads) {
|
||||||
|
session->out << "|" << ++sequence;
|
||||||
|
session->out << "|" ;
|
||||||
|
threadx.output(session);
|
||||||
|
session->out << "|" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
129
EPoll.h
Normal file
129
EPoll.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
#ifndef __EPoll_h__
|
||||||
|
#define __EPoll_h__
|
||||||
|
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "Thread.h"
|
||||||
|
#include "Session.h"
|
||||||
|
#include "Command.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// EPoll
|
||||||
|
///
|
||||||
|
/// Manage socket events from the epoll system call.
|
||||||
|
///
|
||||||
|
/// Use this object to establish a socket server using the epoll network structure of Linux.
|
||||||
|
///
|
||||||
|
/// Use this object to establish the basis of working with multiple sockets of all sorts
|
||||||
|
/// using the epoll capabilities of the Linux platform.
|
||||||
|
/// Socket objects can register with BMAEPoll which will establish a communication mechanism
|
||||||
|
/// with that socket.
|
||||||
|
///
|
||||||
|
/// The maximum number of sockets to communicate with is specified on the
|
||||||
|
/// start method.
|
||||||
|
///
|
||||||
|
/// Threads are used to establish a read queue for epoll. The desired number of threads (or
|
||||||
|
/// queues) is established by a parameter on the start method.
|
||||||
|
///
|
||||||
|
|
||||||
|
class EPoll : public Command {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The constructor for the BMAEPoll object.
|
||||||
|
///
|
||||||
|
|
||||||
|
EPoll();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The destructor for the BMAEPoll object.
|
||||||
|
///
|
||||||
|
|
||||||
|
~EPoll();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use the start() method to initiate the threads and begin epoll queue processing.
|
||||||
|
///
|
||||||
|
/// @param numberOfThreads the number of threads to start for processing epoll entries.
|
||||||
|
/// @param maxSockets the maximum number of open sockets that epoll will manage.
|
||||||
|
///
|
||||||
|
|
||||||
|
bool start(int numberOfThreads, int maxSockets); ///< Start the BMAEPoll processing.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use the stop() method to initiate the shutdown process for the epoll socket management.
|
||||||
|
///
|
||||||
|
/// A complete shutdown of all managed sockets will be initiated by this method call.
|
||||||
|
///
|
||||||
|
|
||||||
|
bool stop(); ///< Stop and shut down the BMAEPoll processing.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// This method returns a true if the stop() method has been called and the epoll system
|
||||||
|
/// is shutting.
|
||||||
|
///
|
||||||
|
|
||||||
|
bool isStopping(); ///< Returns a true if the stop command has been requested.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use registerSocket to add a new socket to the ePoll event watch list. This enables
|
||||||
|
/// a new BMASocket object to receive events when data is received as well as to write
|
||||||
|
/// data output to the socket.
|
||||||
|
///
|
||||||
|
/// @param socket a pointer to a BMASocket object.
|
||||||
|
/// @return a booelean that indicates the socket was registered or not.
|
||||||
|
///
|
||||||
|
|
||||||
|
bool registerSocket(Socket *socket); ///< Register a BMASocket for monitoring by BMAEPoll.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use this method to remove a socket from receiving events from the epoll system.
|
||||||
|
///
|
||||||
|
|
||||||
|
bool unregisterSocket(Socket *socket); ///< Unregister a BMASocket from monitoring by BMAEPoll.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use this method to obtain the current descriptor socket number for the epoll function call.
|
||||||
|
///
|
||||||
|
|
||||||
|
int getDescriptor(); ///< Return the descriptor for the ePoll socket.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The maximum number of sockets that can be managed by the epoll system.
|
||||||
|
///
|
||||||
|
|
||||||
|
int maxSockets; ///< The maximum number of socket allowed.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Receive the epoll events and dispatch the event to the socket making the request.
|
||||||
|
///
|
||||||
|
|
||||||
|
void eventReceived(struct epoll_event event); ///< Dispatch event to appropriate socket.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The processCommand() method displays the thread array to the requesting console via the
|
||||||
|
/// session passed as parameter.
|
||||||
|
///
|
||||||
|
/// @param session the session to write the requested data to.
|
||||||
|
///
|
||||||
|
|
||||||
|
int processCommand(std::string command, Session *session) override; ///<Output the threads array to the console.
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int epfd;
|
||||||
|
int numberOfThreads;
|
||||||
|
std::map<int, Socket *> sockets;
|
||||||
|
std::vector<Thread> threads;
|
||||||
|
volatile bool terminateThreads;
|
||||||
|
std::mutex lock;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
20
Exception.cpp
Normal file
20
Exception.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "Exception.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
Exception::Exception(std::string text, std::string file, int line, int errorNumber) {
|
||||||
|
this->text = text;
|
||||||
|
this->file = file;
|
||||||
|
this->line = line;
|
||||||
|
if(errorNumber == -1)
|
||||||
|
this->errorNumber = errno;
|
||||||
|
else
|
||||||
|
this->errorNumber = errorNumber;
|
||||||
|
|
||||||
|
Log(LOG_EXCEPT) << text;
|
||||||
|
}
|
||||||
|
|
||||||
|
Exception::~Exception() {}
|
||||||
|
|
||||||
|
}
|
24
Exception.h
Normal file
24
Exception.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#ifndef __Exception_h__
|
||||||
|
#define __Exception_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class Exception {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Exception(std::string text, std::string file = __FILE__, int line = __LINE__, int errorNumber = -1);
|
||||||
|
~Exception();
|
||||||
|
|
||||||
|
std::string className;
|
||||||
|
std::string file;
|
||||||
|
int line;
|
||||||
|
std::string text;
|
||||||
|
int errorNumber;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
43
File.cpp
Normal file
43
File.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include "File.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
File::File(std::string fileName, int mode, int authority) {
|
||||||
|
|
||||||
|
this->fileName = fileName;
|
||||||
|
|
||||||
|
struct stat status;
|
||||||
|
stat(fileName.c_str(), &status);
|
||||||
|
|
||||||
|
buffer = NULL;
|
||||||
|
|
||||||
|
setBufferSize(status.st_size);
|
||||||
|
|
||||||
|
fd = open(fileName.c_str(), mode, authority);
|
||||||
|
if(fd < 0) {
|
||||||
|
std::stringstream temp;
|
||||||
|
temp << "Error opening file " << fileName << ".";
|
||||||
|
throw Exception(temp.str(), __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File::~File() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void File::setBufferSize(size_t size) {
|
||||||
|
buffer = (char *)realloc(buffer, size);
|
||||||
|
this->size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void File::read() {
|
||||||
|
size = ::read(fd, buffer, size);
|
||||||
|
setBufferSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void File::write(std::string data) {
|
||||||
|
::write(fd, data.c_str(), data.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
35
File.h
Normal file
35
File.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef __File_h__
|
||||||
|
#define __File_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
|
||||||
|
///
|
||||||
|
/// File
|
||||||
|
///
|
||||||
|
/// File abstraction class for accessing local file system files.
|
||||||
|
///
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class File {
|
||||||
|
|
||||||
|
public:
|
||||||
|
File(std::string fileName, int mode = O_RDONLY, int authority = 0664);
|
||||||
|
~File();
|
||||||
|
void setBufferSize(size_t size);
|
||||||
|
void read();
|
||||||
|
void write(std::string data);
|
||||||
|
|
||||||
|
char *buffer;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
std::string fileName;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
29
Header.cpp
Normal file
29
Header.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include "Header.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
Header::Header(std::string data) : data(data) {
|
||||||
|
// Log(LOG_DEBUG_4) << data;
|
||||||
|
}
|
||||||
|
|
||||||
|
Header::~Header() {}
|
||||||
|
|
||||||
|
std::string Header::requestMethod() {
|
||||||
|
return data.substr(0, data.find(" "));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Header::requestURL() {
|
||||||
|
std::string temp = data.substr(data.find(" ") + 1);
|
||||||
|
return temp.substr(0, temp.find(" "));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Header::requestProtocol() {
|
||||||
|
std::string line1 = data.substr(0, data.find("\r\n"));
|
||||||
|
return line1.substr(line1.rfind(" ") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
29
Header.h
Normal file
29
Header.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef __Header_h__
|
||||||
|
#define __Header_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Object.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class Header : public Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Header(std::string data);
|
||||||
|
~Header();
|
||||||
|
|
||||||
|
std::string data;
|
||||||
|
|
||||||
|
std::string requestMethod();
|
||||||
|
std::string requestURL();
|
||||||
|
std::string requestProtocol();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
// vector<map<string, string>> header;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
31
IPAddress.cpp
Normal file
31
IPAddress.cpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#include "IPAddress.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
IPAddress::IPAddress() {
|
||||||
|
addressLength = sizeof(struct sockaddr_in);
|
||||||
|
}
|
||||||
|
|
||||||
|
IPAddress::~IPAddress() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string IPAddress::getClientAddress() {
|
||||||
|
std::string result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string IPAddress::getClientAddressAndPort() {
|
||||||
|
std::stringstream out;
|
||||||
|
out << inet_ntoa(address.sin_addr);
|
||||||
|
out << ":" << address.sin_port;
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
int IPAddress::getClientPort() {
|
||||||
|
int result = -1;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
26
IPAddress.h
Normal file
26
IPAddress.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef __IPAddress_h__
|
||||||
|
#define __IPAddress_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Object.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class IPAddress : public Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
IPAddress();
|
||||||
|
~IPAddress();
|
||||||
|
|
||||||
|
struct sockaddr_in address;
|
||||||
|
socklen_t addressLength;
|
||||||
|
|
||||||
|
std::string getClientAddress(); ///<Get the client network address as xxx.xxx.xxx.xxx.
|
||||||
|
std::string getClientAddressAndPort(); ///<Get the client network address and port as xxx.xxx.xxx.xxx:ppppp.
|
||||||
|
int getClientPort(); ///<Get the client network port number.
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
79
Log.cpp
Normal file
79
Log.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "ConsoleSession.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
ConsoleServer *Log::consoleServer = NULL;
|
||||||
|
File *Log::logFile = NULL;
|
||||||
|
int Log::seq = 0;
|
||||||
|
|
||||||
|
Log::Log(ConsoleServer *consoleServer) {
|
||||||
|
this->consoleServer = consoleServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::Log(File *logFile) {
|
||||||
|
this->logFile = logFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::Log(int level) {
|
||||||
|
|
||||||
|
output = true;
|
||||||
|
|
||||||
|
auto clock = std::chrono::system_clock::now();
|
||||||
|
time_t theTime = std::chrono::system_clock::to_time_t(clock);
|
||||||
|
std::string timeOut = std::string(ctime(&theTime));
|
||||||
|
timeOut = timeOut.substr(0, timeOut.length() - 1);
|
||||||
|
|
||||||
|
*this << timeOut;
|
||||||
|
*this << " ";
|
||||||
|
|
||||||
|
switch(level) {
|
||||||
|
case LOG_NONE:
|
||||||
|
*this << "[NONE] :";
|
||||||
|
break;
|
||||||
|
case LOG_INFO:
|
||||||
|
*this << "[INFO] :";
|
||||||
|
break;
|
||||||
|
case LOG_WARN:
|
||||||
|
*this << "[WARN] :";
|
||||||
|
break;
|
||||||
|
case LOG_EXCEPT:
|
||||||
|
*this << "[EXCEPT]: ";
|
||||||
|
break;
|
||||||
|
case LOG_DEBUG_1:
|
||||||
|
*this << "[DEBUG1]: ";
|
||||||
|
break;
|
||||||
|
case LOG_DEBUG_2:
|
||||||
|
*this << "[DEBUG2]: ";
|
||||||
|
break;
|
||||||
|
case LOG_DEBUG_3:
|
||||||
|
*this << "[DEBUG3]: ";
|
||||||
|
break;
|
||||||
|
case LOG_DEBUG_4:
|
||||||
|
*this << "[DEBUG4]: ";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*this << "[?] ?";
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::~Log() {
|
||||||
|
|
||||||
|
if(output) {
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
out << seq << "." << this->str() << std::endl;;
|
||||||
|
|
||||||
|
if(consoleServer)
|
||||||
|
consoleServer->sendToConnectedConsoles(out.str());
|
||||||
|
|
||||||
|
if(logFile)
|
||||||
|
logFile->write(out.str());
|
||||||
|
|
||||||
|
std::cout << out.str();
|
||||||
|
++seq;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
94
Log.h
Normal file
94
Log.h
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#ifndef __Log_h__
|
||||||
|
#define __Log_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "File.h"
|
||||||
|
#include "Object.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class ConsoleServer;
|
||||||
|
|
||||||
|
static const int LOG_NONE = 0;
|
||||||
|
static const int LOG_INFO = 1;
|
||||||
|
static const int LOG_WARN = 2;
|
||||||
|
static const int LOG_EXCEPT = 4;
|
||||||
|
static const int LOG_DEBUG_1 = 8;
|
||||||
|
static const int LOG_DEBUG_2 = 16;
|
||||||
|
static const int LOG_DEBUG_3 = 32;
|
||||||
|
static const int LOG_DEBUG_4 = 64;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Log
|
||||||
|
///
|
||||||
|
/// Provides easy to access and use logging features to maintain a
|
||||||
|
/// history of activity and provide information for activity debugging.
|
||||||
|
///
|
||||||
|
|
||||||
|
class Log : public std::ostringstream, public Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Constructor method that accepts a pointer to the applications
|
||||||
|
/// console server. This enables the Log object to send new log
|
||||||
|
/// messages to the connected console sessions.
|
||||||
|
///
|
||||||
|
/// @param consoleServer a pointer to the console server that will
|
||||||
|
/// be used to echo log entries.
|
||||||
|
///
|
||||||
|
|
||||||
|
Log(ConsoleServer *consoleServer);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Constructor method accepts a file object that will be used to
|
||||||
|
/// echo all log entries. This provides a permanent disk file record
|
||||||
|
/// of all logged activity.
|
||||||
|
///
|
||||||
|
|
||||||
|
Log(File *logFile);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Constructor method that is used to send a message to the log.
|
||||||
|
///
|
||||||
|
/// @param level the logging level to associate with this message.
|
||||||
|
///
|
||||||
|
/// To send log message: Log(LOG_INFO) << "This is a log message.";
|
||||||
|
///
|
||||||
|
|
||||||
|
Log(int level);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The destructor for the log object.
|
||||||
|
///
|
||||||
|
|
||||||
|
~Log();
|
||||||
|
|
||||||
|
bool output = false;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Set the consoleServer to point to the instantiated ConsoleServer
|
||||||
|
/// object for the application.
|
||||||
|
///
|
||||||
|
|
||||||
|
static ConsoleServer *consoleServer;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Specify a File object where the log entries will be written as
|
||||||
|
/// a permanent record to disk.
|
||||||
|
///
|
||||||
|
|
||||||
|
static File *logFile;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// A meaningless sequenctial number that starts from - at the
|
||||||
|
/// beginning of the logging process.
|
||||||
|
///
|
||||||
|
|
||||||
|
static int seq;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
19
Object.h
Normal file
19
Object.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef __Object_h__
|
||||||
|
#define __Object_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
std::string name;
|
||||||
|
std::string tag;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
50
Response.cpp
Normal file
50
Response.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#include "Response.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
Response::Response() {}
|
||||||
|
Response::~Response() {}
|
||||||
|
|
||||||
|
std::string Response::getResponse(Mode mode) {
|
||||||
|
return getResponse("", mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Response::getResponse(std::string content, Mode mode) {
|
||||||
|
std::stringstream response;
|
||||||
|
response << protocol << " " << code << " " << text << CRLF;
|
||||||
|
for(std::map<std::string, std::string>::iterator item = header.begin(); item != header.end(); ++item)
|
||||||
|
response << item->first << ": " << item->second << CRLF;
|
||||||
|
if(mimeType != "")
|
||||||
|
response << "Content-Type: " << mimeType << CRLF;
|
||||||
|
if(mode == LENGTH)
|
||||||
|
response << "Content-Length: " << content.length() << CRLF;
|
||||||
|
else
|
||||||
|
response << "Transfer-Encoding: chunked" << CRLF;
|
||||||
|
response << CRLF;
|
||||||
|
response << content;
|
||||||
|
// Log(LOG_DEBUG_4) << response.str();
|
||||||
|
return response.str();
|
||||||
|
}
|
||||||
|
\
|
||||||
|
void Response::setProtocol(std::string protocol) {
|
||||||
|
this->protocol = protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Response::setCode(std::string code) {
|
||||||
|
this->code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Response::setText(std::string text) {
|
||||||
|
this->text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Response::setMimeType(std::string mimeType) {
|
||||||
|
this->mimeType = mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Response::addHeaderItem(std::string key, std::string value) {
|
||||||
|
header.insert(std::pair<std::string, std::string>(key, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
108
Response.h
Normal file
108
Response.h
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
#ifndef __Response_h__
|
||||||
|
#define __Response_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Object.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Response
|
||||||
|
///
|
||||||
|
/// Use this object to build a response output for a protocol that uses headers
|
||||||
|
/// and responses as the main communications protocol.
|
||||||
|
///
|
||||||
|
|
||||||
|
class Response : public Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum Mode { LENGTH, STREAMING };
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The constructor for the object.
|
||||||
|
///
|
||||||
|
|
||||||
|
Response();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The destructor for the object.
|
||||||
|
///
|
||||||
|
|
||||||
|
~Response();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Returns the response generated from the contained values that
|
||||||
|
/// do not return a content length. Using this constructor ensures
|
||||||
|
/// a zero length Content-Length value.
|
||||||
|
///
|
||||||
|
/// @return the complete response string to send to client.
|
||||||
|
///
|
||||||
|
|
||||||
|
std::string getResponse(Mode mode = LENGTH);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Returns the response plus the content passed as a parameter.
|
||||||
|
///
|
||||||
|
/// This method will automatically generate the proper Content-Length
|
||||||
|
/// value for the response.
|
||||||
|
///
|
||||||
|
/// @param content the content that will be provided on the response
|
||||||
|
/// message to the client.
|
||||||
|
///
|
||||||
|
/// @return the complete response string to send to client.
|
||||||
|
///
|
||||||
|
|
||||||
|
std::string getResponse(std::string content, Mode mode = LENGTH);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Sets the protocol value for the response message. The protocol
|
||||||
|
/// should match the header received.
|
||||||
|
///
|
||||||
|
/// @param protocol the protocol value to return in response.
|
||||||
|
///
|
||||||
|
|
||||||
|
void setProtocol(std::string protocol);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Sets the return code value for the response.
|
||||||
|
///
|
||||||
|
/// @param code the response code value to return in the response.
|
||||||
|
///
|
||||||
|
|
||||||
|
void setCode(std::string code);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Sets the return code string value for the response.
|
||||||
|
///
|
||||||
|
/// @param text the text value for the response code to return on
|
||||||
|
/// the response.
|
||||||
|
///
|
||||||
|
|
||||||
|
void setText(std::string text);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Specifies the type of data that will be returned in this response.
|
||||||
|
///
|
||||||
|
/// @param mimeType the mime type for the data.
|
||||||
|
///
|
||||||
|
|
||||||
|
void setMimeType(std::string mimeType);
|
||||||
|
|
||||||
|
void addHeaderItem(std::string key, std::string value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string protocol;
|
||||||
|
std::string code;
|
||||||
|
std::string text;
|
||||||
|
std::string mimeType;
|
||||||
|
|
||||||
|
std::string CRLF = "\r\n";
|
||||||
|
|
||||||
|
std::map<std::string, std::string> header;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
282
ServerCore.mk
Normal file
282
ServerCore.mk
Normal file
@ -0,0 +1,282 @@
|
|||||||
|
##
|
||||||
|
## Auto Generated makefile by CodeLite IDE
|
||||||
|
## any manual changes will be erased
|
||||||
|
##
|
||||||
|
## Debug
|
||||||
|
ProjectName :=ServerCore
|
||||||
|
ConfigurationName :=Debug
|
||||||
|
WorkspacePath :=/home/barant/Development/BMA/server_core
|
||||||
|
ProjectPath :=/home/barant/Development/BMA/server_core/ServerCore
|
||||||
|
IntermediateDirectory :=./Debug
|
||||||
|
OutDir := $(IntermediateDirectory)
|
||||||
|
CurrentFileName :=
|
||||||
|
CurrentFilePath :=
|
||||||
|
CurrentFileFullPath :=
|
||||||
|
User :=Brad Arant
|
||||||
|
Date :=07/02/19
|
||||||
|
CodeLitePath :=/home/barant/.codelite
|
||||||
|
LinkerName :=g++
|
||||||
|
SharedObjectLinkerName :=g++ -shared -fPIC
|
||||||
|
ObjectSuffix :=.o
|
||||||
|
DependSuffix :=.o.d
|
||||||
|
PreprocessSuffix :=.o.i
|
||||||
|
DebugSwitch :=-gstab
|
||||||
|
IncludeSwitch :=-I
|
||||||
|
LibrarySwitch :=-l
|
||||||
|
OutputSwitch :=-o
|
||||||
|
LibraryPathSwitch :=-L
|
||||||
|
PreprocessorSwitch :=-D
|
||||||
|
SourceSwitch :=-c
|
||||||
|
OutputFile :=$(IntermediateDirectory)/lib$(ProjectName).a
|
||||||
|
Preprocessors :=
|
||||||
|
ObjectSwitch :=-o
|
||||||
|
ArchiveOutputSwitch :=
|
||||||
|
PreprocessOnlySwitch :=-E
|
||||||
|
ObjectsFileList :="ServerCore.txt"
|
||||||
|
PCHCompileFlags :=
|
||||||
|
MakeDirCommand :=mkdir -p
|
||||||
|
LinkOptions :=
|
||||||
|
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
|
||||||
|
IncludePCH :=
|
||||||
|
RcIncludePath :=
|
||||||
|
Libs :=
|
||||||
|
ArLibs :=
|
||||||
|
LibPath := $(LibraryPathSwitch).
|
||||||
|
|
||||||
|
##
|
||||||
|
## Common variables
|
||||||
|
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
|
||||||
|
##
|
||||||
|
AR := ar rcus
|
||||||
|
CXX := g++
|
||||||
|
CC := gcc
|
||||||
|
CXXFLAGS := -g $(Preprocessors)
|
||||||
|
CFLAGS := -g $(Preprocessors)
|
||||||
|
ASFLAGS :=
|
||||||
|
AS := as
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
## User defined environment variables
|
||||||
|
##
|
||||||
|
CodeLiteDir:=/usr/share/codelite
|
||||||
|
Objects0=$(IntermediateDirectory)/Command.cpp$(ObjectSuffix) $(IntermediateDirectory)/ConsoleServer.cpp$(ObjectSuffix) $(IntermediateDirectory)/ConsoleSession.cpp$(ObjectSuffix) $(IntermediateDirectory)/EPoll.cpp$(ObjectSuffix) $(IntermediateDirectory)/Exception.cpp$(ObjectSuffix) $(IntermediateDirectory)/File.cpp$(ObjectSuffix) $(IntermediateDirectory)/Header.cpp$(ObjectSuffix) $(IntermediateDirectory)/IPAddress.cpp$(ObjectSuffix) $(IntermediateDirectory)/Log.cpp$(ObjectSuffix) $(IntermediateDirectory)/Response.cpp$(ObjectSuffix) \
|
||||||
|
$(IntermediateDirectory)/Session.cpp$(ObjectSuffix) $(IntermediateDirectory)/Socket.cpp$(ObjectSuffix) $(IntermediateDirectory)/TCPServerSocket.cpp$(ObjectSuffix) $(IntermediateDirectory)/TCPSocket.cpp$(ObjectSuffix) $(IntermediateDirectory)/Thread.cpp$(ObjectSuffix) $(IntermediateDirectory)/Timer.cpp$(ObjectSuffix) $(IntermediateDirectory)/TLSServerSocket.cpp$(ObjectSuffix) $(IntermediateDirectory)/TLSSession.cpp$(ObjectSuffix) $(IntermediateDirectory)/UDPServerSocket.cpp$(ObjectSuffix) $(IntermediateDirectory)/UDPSocket.cpp$(ObjectSuffix) \
|
||||||
|
$(IntermediateDirectory)/CommandList.cpp$(ObjectSuffix) $(IntermediateDirectory)/TerminalSession.cpp$(ObjectSuffix)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Objects=$(Objects0)
|
||||||
|
|
||||||
|
##
|
||||||
|
## Main Build Targets
|
||||||
|
##
|
||||||
|
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
|
||||||
|
all: $(IntermediateDirectory) $(OutputFile)
|
||||||
|
|
||||||
|
$(OutputFile): $(Objects)
|
||||||
|
@$(MakeDirCommand) $(@D)
|
||||||
|
@echo "" > $(IntermediateDirectory)/.d
|
||||||
|
@echo $(Objects0) > $(ObjectsFileList)
|
||||||
|
$(AR) $(ArchiveOutputSwitch)$(OutputFile) @$(ObjectsFileList) $(ArLibs)
|
||||||
|
@$(MakeDirCommand) "/home/barant/Development/BMA/server_core/.build-debug"
|
||||||
|
@echo rebuilt > "/home/barant/Development/BMA/server_core/.build-debug/ServerCore"
|
||||||
|
|
||||||
|
MakeIntermediateDirs:
|
||||||
|
@test -d ./Debug || $(MakeDirCommand) ./Debug
|
||||||
|
|
||||||
|
|
||||||
|
./Debug:
|
||||||
|
@test -d ./Debug || $(MakeDirCommand) ./Debug
|
||||||
|
|
||||||
|
PreBuild:
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
## Objects
|
||||||
|
##
|
||||||
|
$(IntermediateDirectory)/Command.cpp$(ObjectSuffix): Command.cpp $(IntermediateDirectory)/Command.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Command.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Command.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Command.cpp$(DependSuffix): Command.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Command.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Command.cpp$(DependSuffix) -MM Command.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Command.cpp$(PreprocessSuffix): Command.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Command.cpp$(PreprocessSuffix) Command.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/ConsoleServer.cpp$(ObjectSuffix): ConsoleServer.cpp $(IntermediateDirectory)/ConsoleServer.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/ConsoleServer.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/ConsoleServer.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/ConsoleServer.cpp$(DependSuffix): ConsoleServer.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/ConsoleServer.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/ConsoleServer.cpp$(DependSuffix) -MM ConsoleServer.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/ConsoleServer.cpp$(PreprocessSuffix): ConsoleServer.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/ConsoleServer.cpp$(PreprocessSuffix) ConsoleServer.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/ConsoleSession.cpp$(ObjectSuffix): ConsoleSession.cpp $(IntermediateDirectory)/ConsoleSession.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/ConsoleSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/ConsoleSession.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/ConsoleSession.cpp$(DependSuffix): ConsoleSession.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/ConsoleSession.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/ConsoleSession.cpp$(DependSuffix) -MM ConsoleSession.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/ConsoleSession.cpp$(PreprocessSuffix): ConsoleSession.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/ConsoleSession.cpp$(PreprocessSuffix) ConsoleSession.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/EPoll.cpp$(ObjectSuffix): EPoll.cpp $(IntermediateDirectory)/EPoll.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/EPoll.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/EPoll.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/EPoll.cpp$(DependSuffix): EPoll.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/EPoll.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/EPoll.cpp$(DependSuffix) -MM EPoll.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/EPoll.cpp$(PreprocessSuffix): EPoll.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/EPoll.cpp$(PreprocessSuffix) EPoll.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Exception.cpp$(ObjectSuffix): Exception.cpp $(IntermediateDirectory)/Exception.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Exception.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Exception.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Exception.cpp$(DependSuffix): Exception.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Exception.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Exception.cpp$(DependSuffix) -MM Exception.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Exception.cpp$(PreprocessSuffix): Exception.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Exception.cpp$(PreprocessSuffix) Exception.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/File.cpp$(ObjectSuffix): File.cpp $(IntermediateDirectory)/File.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/File.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/File.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/File.cpp$(DependSuffix): File.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/File.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/File.cpp$(DependSuffix) -MM File.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/File.cpp$(PreprocessSuffix): File.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/File.cpp$(PreprocessSuffix) File.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Header.cpp$(ObjectSuffix): Header.cpp $(IntermediateDirectory)/Header.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Header.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Header.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Header.cpp$(DependSuffix): Header.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Header.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Header.cpp$(DependSuffix) -MM Header.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Header.cpp$(PreprocessSuffix): Header.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Header.cpp$(PreprocessSuffix) Header.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/IPAddress.cpp$(ObjectSuffix): IPAddress.cpp $(IntermediateDirectory)/IPAddress.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/IPAddress.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/IPAddress.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/IPAddress.cpp$(DependSuffix): IPAddress.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/IPAddress.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/IPAddress.cpp$(DependSuffix) -MM IPAddress.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/IPAddress.cpp$(PreprocessSuffix): IPAddress.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/IPAddress.cpp$(PreprocessSuffix) IPAddress.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Log.cpp$(ObjectSuffix): Log.cpp $(IntermediateDirectory)/Log.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Log.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Log.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Log.cpp$(DependSuffix): Log.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Log.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Log.cpp$(DependSuffix) -MM Log.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Log.cpp$(PreprocessSuffix): Log.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Log.cpp$(PreprocessSuffix) Log.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Response.cpp$(ObjectSuffix): Response.cpp $(IntermediateDirectory)/Response.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Response.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Response.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Response.cpp$(DependSuffix): Response.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Response.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Response.cpp$(DependSuffix) -MM Response.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Response.cpp$(PreprocessSuffix): Response.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Response.cpp$(PreprocessSuffix) Response.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Session.cpp$(ObjectSuffix): Session.cpp $(IntermediateDirectory)/Session.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Session.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Session.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Session.cpp$(DependSuffix): Session.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Session.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Session.cpp$(DependSuffix) -MM Session.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Session.cpp$(PreprocessSuffix): Session.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Session.cpp$(PreprocessSuffix) Session.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Socket.cpp$(ObjectSuffix): Socket.cpp $(IntermediateDirectory)/Socket.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Socket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Socket.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Socket.cpp$(DependSuffix): Socket.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Socket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Socket.cpp$(DependSuffix) -MM Socket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Socket.cpp$(PreprocessSuffix): Socket.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Socket.cpp$(PreprocessSuffix) Socket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TCPServerSocket.cpp$(ObjectSuffix): TCPServerSocket.cpp $(IntermediateDirectory)/TCPServerSocket.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TCPServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TCPServerSocket.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/TCPServerSocket.cpp$(DependSuffix): TCPServerSocket.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TCPServerSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TCPServerSocket.cpp$(DependSuffix) -MM TCPServerSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TCPServerSocket.cpp$(PreprocessSuffix): TCPServerSocket.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TCPServerSocket.cpp$(PreprocessSuffix) TCPServerSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TCPSocket.cpp$(ObjectSuffix): TCPSocket.cpp $(IntermediateDirectory)/TCPSocket.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TCPSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TCPSocket.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/TCPSocket.cpp$(DependSuffix): TCPSocket.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TCPSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TCPSocket.cpp$(DependSuffix) -MM TCPSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TCPSocket.cpp$(PreprocessSuffix): TCPSocket.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TCPSocket.cpp$(PreprocessSuffix) TCPSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Thread.cpp$(ObjectSuffix): Thread.cpp $(IntermediateDirectory)/Thread.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Thread.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Thread.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Thread.cpp$(DependSuffix): Thread.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Thread.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Thread.cpp$(DependSuffix) -MM Thread.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Thread.cpp$(PreprocessSuffix): Thread.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Thread.cpp$(PreprocessSuffix) Thread.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Timer.cpp$(ObjectSuffix): Timer.cpp $(IntermediateDirectory)/Timer.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/Timer.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/Timer.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/Timer.cpp$(DependSuffix): Timer.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/Timer.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/Timer.cpp$(DependSuffix) -MM Timer.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/Timer.cpp$(PreprocessSuffix): Timer.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/Timer.cpp$(PreprocessSuffix) Timer.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TLSServerSocket.cpp$(ObjectSuffix): TLSServerSocket.cpp $(IntermediateDirectory)/TLSServerSocket.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TLSServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TLSServerSocket.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/TLSServerSocket.cpp$(DependSuffix): TLSServerSocket.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TLSServerSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TLSServerSocket.cpp$(DependSuffix) -MM TLSServerSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TLSServerSocket.cpp$(PreprocessSuffix): TLSServerSocket.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TLSServerSocket.cpp$(PreprocessSuffix) TLSServerSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TLSSession.cpp$(ObjectSuffix): TLSSession.cpp $(IntermediateDirectory)/TLSSession.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TLSSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TLSSession.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/TLSSession.cpp$(DependSuffix): TLSSession.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TLSSession.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TLSSession.cpp$(DependSuffix) -MM TLSSession.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TLSSession.cpp$(PreprocessSuffix): TLSSession.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TLSSession.cpp$(PreprocessSuffix) TLSSession.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/UDPServerSocket.cpp$(ObjectSuffix): UDPServerSocket.cpp $(IntermediateDirectory)/UDPServerSocket.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/UDPServerSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/UDPServerSocket.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/UDPServerSocket.cpp$(DependSuffix): UDPServerSocket.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/UDPServerSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/UDPServerSocket.cpp$(DependSuffix) -MM UDPServerSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/UDPServerSocket.cpp$(PreprocessSuffix): UDPServerSocket.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/UDPServerSocket.cpp$(PreprocessSuffix) UDPServerSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/UDPSocket.cpp$(ObjectSuffix): UDPSocket.cpp $(IntermediateDirectory)/UDPSocket.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/UDPSocket.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/UDPSocket.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/UDPSocket.cpp$(DependSuffix): UDPSocket.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/UDPSocket.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/UDPSocket.cpp$(DependSuffix) -MM UDPSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/UDPSocket.cpp$(PreprocessSuffix): UDPSocket.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/UDPSocket.cpp$(PreprocessSuffix) UDPSocket.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/CommandList.cpp$(ObjectSuffix): CommandList.cpp $(IntermediateDirectory)/CommandList.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/CommandList.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/CommandList.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/CommandList.cpp$(DependSuffix): CommandList.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/CommandList.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/CommandList.cpp$(DependSuffix) -MM CommandList.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/CommandList.cpp$(PreprocessSuffix): CommandList.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/CommandList.cpp$(PreprocessSuffix) CommandList.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TerminalSession.cpp$(ObjectSuffix): TerminalSession.cpp $(IntermediateDirectory)/TerminalSession.cpp$(DependSuffix)
|
||||||
|
$(CXX) $(IncludePCH) $(SourceSwitch) "/home/barant/Development/BMA/server_core/ServerCore/TerminalSession.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/TerminalSession.cpp$(ObjectSuffix) $(IncludePath)
|
||||||
|
$(IntermediateDirectory)/TerminalSession.cpp$(DependSuffix): TerminalSession.cpp
|
||||||
|
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/TerminalSession.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/TerminalSession.cpp$(DependSuffix) -MM TerminalSession.cpp
|
||||||
|
|
||||||
|
$(IntermediateDirectory)/TerminalSession.cpp$(PreprocessSuffix): TerminalSession.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/TerminalSession.cpp$(PreprocessSuffix) TerminalSession.cpp
|
||||||
|
|
||||||
|
|
||||||
|
-include $(IntermediateDirectory)/*$(DependSuffix)
|
||||||
|
##
|
||||||
|
## Clean
|
||||||
|
##
|
||||||
|
clean:
|
||||||
|
$(RM) -r ./Debug/
|
||||||
|
|
||||||
|
|
144
ServerCore.project
Normal file
144
ServerCore.project
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CodeLite_Project Name="ServerCore" Version="10.0.0" InternalType="Library">
|
||||||
|
<Description/>
|
||||||
|
<Dependencies/>
|
||||||
|
<Settings Type="Static Library">
|
||||||
|
<GlobalSettings>
|
||||||
|
<Compiler Options="" C_Options="" Assembler="">
|
||||||
|
<IncludePath Value="."/>
|
||||||
|
</Compiler>
|
||||||
|
<Linker Options="">
|
||||||
|
<LibraryPath Value="."/>
|
||||||
|
</Linker>
|
||||||
|
<ResourceCompiler Options=""/>
|
||||||
|
</GlobalSettings>
|
||||||
|
<Configuration Name="Debug" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Static Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
|
||||||
|
<Compiler Options="-g" C_Options="-g" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
|
||||||
|
<IncludePath Value="."/>
|
||||||
|
</Compiler>
|
||||||
|
<Linker Options="" Required="yes"/>
|
||||||
|
<ResourceCompiler Options="" Required="no"/>
|
||||||
|
<General OutputFile="$(IntermediateDirectory)/lib$(ProjectName).a" IntermediateDirectory="./Debug" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
|
||||||
|
<BuildSystem Name="Default"/>
|
||||||
|
<Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>">
|
||||||
|
<![CDATA[]]>
|
||||||
|
</Environment>
|
||||||
|
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
|
||||||
|
<DebuggerSearchPaths/>
|
||||||
|
<PostConnectCommands/>
|
||||||
|
<StartupCommands/>
|
||||||
|
</Debugger>
|
||||||
|
<PreBuild/>
|
||||||
|
<PostBuild/>
|
||||||
|
<CustomBuild Enabled="no">
|
||||||
|
<RebuildCommand/>
|
||||||
|
<CleanCommand/>
|
||||||
|
<BuildCommand/>
|
||||||
|
<PreprocessFileCommand/>
|
||||||
|
<SingleFileCommand/>
|
||||||
|
<MakefileGenerationCommand/>
|
||||||
|
<ThirdPartyToolName/>
|
||||||
|
<WorkingDirectory/>
|
||||||
|
</CustomBuild>
|
||||||
|
<AdditionalRules>
|
||||||
|
<CustomPostBuild/>
|
||||||
|
<CustomPreBuild/>
|
||||||
|
</AdditionalRules>
|
||||||
|
<Completion EnableCpp11="no" EnableCpp14="no">
|
||||||
|
<ClangCmpFlagsC/>
|
||||||
|
<ClangCmpFlags/>
|
||||||
|
<ClangPP/>
|
||||||
|
<SearchPaths/>
|
||||||
|
</Completion>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration Name="Release" CompilerType="gnu g++" DebuggerType="GNU gdb debugger" Type="Static Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
|
||||||
|
<Compiler Options="" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
|
||||||
|
<IncludePath Value="."/>
|
||||||
|
</Compiler>
|
||||||
|
<Linker Options="" Required="yes"/>
|
||||||
|
<ResourceCompiler Options="" Required="no"/>
|
||||||
|
<General OutputFile="$(IntermediateDirectory)/lib$(ProjectName).a" IntermediateDirectory="./Release" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
|
||||||
|
<BuildSystem Name="Default"/>
|
||||||
|
<Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>">
|
||||||
|
<![CDATA[]]>
|
||||||
|
</Environment>
|
||||||
|
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
|
||||||
|
<DebuggerSearchPaths/>
|
||||||
|
<PostConnectCommands/>
|
||||||
|
<StartupCommands/>
|
||||||
|
</Debugger>
|
||||||
|
<PreBuild/>
|
||||||
|
<PostBuild/>
|
||||||
|
<CustomBuild Enabled="no">
|
||||||
|
<RebuildCommand/>
|
||||||
|
<CleanCommand/>
|
||||||
|
<BuildCommand/>
|
||||||
|
<PreprocessFileCommand/>
|
||||||
|
<SingleFileCommand/>
|
||||||
|
<MakefileGenerationCommand/>
|
||||||
|
<ThirdPartyToolName/>
|
||||||
|
<WorkingDirectory/>
|
||||||
|
</CustomBuild>
|
||||||
|
<AdditionalRules>
|
||||||
|
<CustomPostBuild/>
|
||||||
|
<CustomPreBuild/>
|
||||||
|
</AdditionalRules>
|
||||||
|
<Completion EnableCpp11="no" EnableCpp14="no">
|
||||||
|
<ClangCmpFlagsC/>
|
||||||
|
<ClangCmpFlags/>
|
||||||
|
<ClangPP/>
|
||||||
|
<SearchPaths/>
|
||||||
|
</Completion>
|
||||||
|
</Configuration>
|
||||||
|
</Settings>
|
||||||
|
<VirtualDirectory Name="src">
|
||||||
|
<File Name="Command.cpp"/>
|
||||||
|
<File Name="Command.h"/>
|
||||||
|
<File Name="ConsoleServer.cpp"/>
|
||||||
|
<File Name="ConsoleServer.h"/>
|
||||||
|
<File Name="ConsoleSession.cpp"/>
|
||||||
|
<File Name="ConsoleSession.h"/>
|
||||||
|
<File Name="EPoll.cpp"/>
|
||||||
|
<File Name="EPoll.h"/>
|
||||||
|
<File Name="Exception.cpp"/>
|
||||||
|
<File Name="Exception.h"/>
|
||||||
|
<File Name="File.cpp"/>
|
||||||
|
<File Name="File.h"/>
|
||||||
|
<File Name="Header.cpp"/>
|
||||||
|
<File Name="Header.h"/>
|
||||||
|
<File Name="includes"/>
|
||||||
|
<File Name="IPAddress.cpp"/>
|
||||||
|
<File Name="IPAddress.h"/>
|
||||||
|
<File Name="Log.cpp"/>
|
||||||
|
<File Name="Log.h"/>
|
||||||
|
<File Name="Object.h"/>
|
||||||
|
<File Name="Response.cpp"/>
|
||||||
|
<File Name="Response.h"/>
|
||||||
|
<File Name="ServerCore.txt"/>
|
||||||
|
<File Name="Session.cpp"/>
|
||||||
|
<File Name="Session.h"/>
|
||||||
|
<File Name="SessionFilter.h"/>
|
||||||
|
<File Name="Socket.cpp"/>
|
||||||
|
<File Name="Socket.h"/>
|
||||||
|
<File Name="TCPServerSocket.cpp"/>
|
||||||
|
<File Name="TCPServerSocket.h"/>
|
||||||
|
<File Name="TCPSocket.cpp"/>
|
||||||
|
<File Name="TCPSocket.h"/>
|
||||||
|
<File Name="Thread.cpp"/>
|
||||||
|
<File Name="Thread.h"/>
|
||||||
|
<File Name="Timer.cpp"/>
|
||||||
|
<File Name="Timer.h"/>
|
||||||
|
<File Name="TLSServerSocket.cpp"/>
|
||||||
|
<File Name="TLSServerSocket.h"/>
|
||||||
|
<File Name="TLSSession.cpp"/>
|
||||||
|
<File Name="TLSSession.h"/>
|
||||||
|
<File Name="UDPServerSocket.cpp"/>
|
||||||
|
<File Name="UDPServerSocket.h"/>
|
||||||
|
<File Name="UDPSocket.cpp"/>
|
||||||
|
<File Name="UDPSocket.h"/>
|
||||||
|
<File Name="CommandList.h"/>
|
||||||
|
<File Name="CommandList.cpp"/>
|
||||||
|
<File Name="TerminalSession.h"/>
|
||||||
|
<File Name="TerminalSession.cpp"/>
|
||||||
|
</VirtualDirectory>
|
||||||
|
</CodeLite_Project>
|
1
ServerCore.txt
Normal file
1
ServerCore.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
./Debug/Command.cpp.o ./Debug/ConsoleServer.cpp.o ./Debug/ConsoleSession.cpp.o ./Debug/EPoll.cpp.o ./Debug/Exception.cpp.o ./Debug/File.cpp.o ./Debug/Header.cpp.o ./Debug/IPAddress.cpp.o ./Debug/Log.cpp.o ./Debug/Response.cpp.o ./Debug/Session.cpp.o ./Debug/Socket.cpp.o ./Debug/TCPServerSocket.cpp.o ./Debug/TCPSocket.cpp.o ./Debug/Thread.cpp.o ./Debug/Timer.cpp.o ./Debug/TLSServerSocket.cpp.o ./Debug/TLSSession.cpp.o ./Debug/UDPServerSocket.cpp.o ./Debug/UDPSocket.cpp.o ./Debug/CommandList.cpp.o ./Debug/TerminalSession.cpp.o
|
61
Session.cpp
Normal file
61
Session.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "Session.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "TCPServerSocket.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
Session::Session(EPoll &ePoll, TCPServerSocket &server) : TCPSocket(ePoll), server(server) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Session::~Session() {
|
||||||
|
server.removeFromSessionList(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::init() {}
|
||||||
|
|
||||||
|
void Session::output(Session *session) {
|
||||||
|
session->out << "|" << ipAddress.getClientAddressAndPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
TCPServerSocket &Session::getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::protocol(std::string data = "") {
|
||||||
|
if(data.length() > 0)
|
||||||
|
if(!server.commands.processRequest(data, this))
|
||||||
|
server.sessionErrorHandler("Invalid data received.", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::onConnected() {
|
||||||
|
protocol();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::onDataReceived(std::string data) {
|
||||||
|
protocol(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::sendToAll() {
|
||||||
|
for(auto session : server.sessions) {
|
||||||
|
if(session != this)
|
||||||
|
session->write(out.str());
|
||||||
|
}
|
||||||
|
out.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::sendToAll(SessionFilter *filter) {
|
||||||
|
for(auto session : server.sessions) {
|
||||||
|
if(filter->test(*session)) {
|
||||||
|
if(session != this)
|
||||||
|
session->write(out.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Session::send() {
|
||||||
|
write(out.str());
|
||||||
|
out.str("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
79
Session.h
Normal file
79
Session.h
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#ifndef __Session_h__
|
||||||
|
#define __Session_h__
|
||||||
|
|
||||||
|
#include "TCPSocket.h"
|
||||||
|
//#include "TCPServerSocket.h"
|
||||||
|
#include "SessionFilter.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class TCPServerSocket;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Session
|
||||||
|
///
|
||||||
|
/// Session defines the nature of the interaction with the client
|
||||||
|
/// and stores persistent data for a defined session. BMASession objects
|
||||||
|
/// are not sockets but instead provide a communications control
|
||||||
|
/// mechanism. Protocol conversations are provided through extensions
|
||||||
|
/// from this object.
|
||||||
|
///
|
||||||
|
|
||||||
|
class Session : public TCPSocket {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Session(EPoll &ePoll, TCPServerSocket &server);
|
||||||
|
~Session();
|
||||||
|
|
||||||
|
virtual void init();
|
||||||
|
|
||||||
|
virtual void output(Session *session);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The send method is used to output the contents of the out stream
|
||||||
|
/// to the session containing the stream.
|
||||||
|
///
|
||||||
|
|
||||||
|
void send();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use this sendToAll method to output the contents of the out stream
|
||||||
|
/// to all the connections on the server excluding the sender session.
|
||||||
|
///
|
||||||
|
|
||||||
|
void sendToAll();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use this sendToAll method to output the contents of the out stream
|
||||||
|
/// to all the connections on the server excluding the sender session
|
||||||
|
/// and the entries identified by the passed in filter object.
|
||||||
|
///
|
||||||
|
|
||||||
|
void sendToAll(SessionFilter *filter);
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
|
||||||
|
TCPServerSocket &getServer();
|
||||||
|
TCPServerSocket &server;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void onDataReceived(std::string data) override;
|
||||||
|
void onConnected() override;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Override the protocol method to manage and control the session communications
|
||||||
|
/// in your inherited session. If you do not override this method then the Session
|
||||||
|
/// default will process the 'commands' added to the server object using the
|
||||||
|
/// processRequest method on the session input.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void protocol(std::string data);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
20
SessionFilter.h
Normal file
20
SessionFilter.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef __SessionFilter_h__
|
||||||
|
#define __SessionFilter_h__
|
||||||
|
|
||||||
|
//#include "Session.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class Session;
|
||||||
|
|
||||||
|
class SessionFilter : public Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual bool test(Session &session) {
|
||||||
|
return true;};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
192
Socket.cpp
Normal file
192
Socket.cpp
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
#include "EPoll.h"
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
Socket::Socket(EPoll &ePoll) : ePoll(ePoll) {
|
||||||
|
Log(LOG_DEBUG_2) << "BMASocket object created.";
|
||||||
|
Log(LOG_DEBUG_3) << "Buffer size set to default (4096).";
|
||||||
|
buffer = (char *)malloc(4096);
|
||||||
|
length = 4096;
|
||||||
|
}
|
||||||
|
|
||||||
|
Socket::~Socket() {
|
||||||
|
ePoll.unregisterSocket(this);
|
||||||
|
close(descriptor);
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::setDescriptor(int descriptor) {
|
||||||
|
Log(LOG_DEBUG_3) << "Descriptor set to " << descriptor << " for Socket.";
|
||||||
|
if(descriptor < 3)
|
||||||
|
throw Exception("Descriptor out of range", __FILE__, __LINE__);
|
||||||
|
this->descriptor = descriptor;
|
||||||
|
onTLSInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Socket::getDescriptor() {
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::onTLSInit() {}
|
||||||
|
|
||||||
|
void Socket::setBufferSize(int length) {
|
||||||
|
buffer = (char *)realloc(buffer, length);
|
||||||
|
this->length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::onRegistered() {
|
||||||
|
onConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::onUnregistered() {
|
||||||
|
// onDisconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::eventReceived(struct epoll_event event) {
|
||||||
|
|
||||||
|
// std::stringstream stream;
|
||||||
|
// stream << "Event received on socket " << event.data.fd << ": ";
|
||||||
|
// if(event.events & EPOLLRDHUP) stream << "EPOLLRDHUP ";
|
||||||
|
// if(event.events & EPOLLIN) stream << "EPOLLIN ";
|
||||||
|
// if(event.events & EPOLLOUT) stream << "EPOLLOUT ";
|
||||||
|
// if(event.events & EPOLLERR) stream << "EPOLLERR ";
|
||||||
|
// stream << "[" << event.events << "]";
|
||||||
|
// BMALog(LOG_DEBUG_4) << stream.str();
|
||||||
|
//
|
||||||
|
if(event.events & EPOLLRDHUP) {
|
||||||
|
Log(LOG_DEBUG_2) << "Socket " << descriptor << " received disconnect from client.";
|
||||||
|
shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event.events & EPOLLIN)
|
||||||
|
receiveData(buffer, length);
|
||||||
|
|
||||||
|
if(event.events & EPOLLOUT)
|
||||||
|
writeSocket();
|
||||||
|
|
||||||
|
enable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::enable(bool mode) {
|
||||||
|
if(mode) {
|
||||||
|
if(fifo.empty())
|
||||||
|
active ? resetRead(): setRead();
|
||||||
|
else
|
||||||
|
active ? resetReadWrite(5): setReadWrite();
|
||||||
|
active = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::receiveData(char *buffer, int bufferLength) {
|
||||||
|
|
||||||
|
if(bufferLength <= 0)
|
||||||
|
throw Exception("Request to receive data with a zero buffer length.", __FILE__, __LINE__, -1);
|
||||||
|
|
||||||
|
int len;
|
||||||
|
int error = -1;
|
||||||
|
|
||||||
|
if((len = ::read(getDescriptor(), buffer, bufferLength)) >= 0)
|
||||||
|
onDataReceived(std::string(buffer, len));
|
||||||
|
else {
|
||||||
|
|
||||||
|
error = errno;
|
||||||
|
|
||||||
|
switch (error) {
|
||||||
|
|
||||||
|
// When a listening socket receives a connection
|
||||||
|
// request we get one of these.
|
||||||
|
//
|
||||||
|
case ENOTCONN:
|
||||||
|
onDataReceived(std::string(buffer, 0));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ECONNRESET:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw Exception("Error in read of data from socket.", __FILE__, __LINE__, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::onConnected() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::writeSocket() {
|
||||||
|
lock.lock();
|
||||||
|
if(fifo.size() > 0) {
|
||||||
|
::write(descriptor, fifo.front().c_str(), fifo.front().length());
|
||||||
|
fifo.pop();
|
||||||
|
enable(true);
|
||||||
|
}
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::write(std::string data) {
|
||||||
|
lock.lock();
|
||||||
|
fifo.emplace(data);
|
||||||
|
enable(true);
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::output(std::stringstream &out) {
|
||||||
|
out << "|" << descriptor << "|";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::setRead() {
|
||||||
|
event.data.fd = descriptor;
|
||||||
|
event.events = EPOLLIN | EPOLLONESHOT | EPOLLRDHUP | EPOLLET;
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_DEL, descriptor, NULL);
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_ADD, event.data.fd, &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::setWrite() {
|
||||||
|
event.data.fd = descriptor;
|
||||||
|
event.events = EPOLLOUT | EPOLLONESHOT | EPOLLRDHUP | EPOLLET;
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_DEL, descriptor, NULL);
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_ADD, descriptor, &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::setReadWrite() {
|
||||||
|
event.data.fd = descriptor;
|
||||||
|
event.events = EPOLLIN | EPOLLWRNORM | EPOLLONESHOT | EPOLLRDHUP | EPOLLET;
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_DEL, descriptor, NULL);
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_ADD, descriptor, &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::resetRead() {
|
||||||
|
event.data.fd = descriptor;
|
||||||
|
event.events = EPOLLIN | EPOLLONESHOT | EPOLLRDHUP | EPOLLET;
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_MOD, descriptor, &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::resetWrite() {
|
||||||
|
event.data.fd = descriptor;
|
||||||
|
event.events = EPOLLOUT | EPOLLONESHOT | EPOLLRDHUP | EPOLLET;
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_MOD, descriptor, &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::resetReadWrite(int x) {
|
||||||
|
event.data.fd = descriptor;
|
||||||
|
event.events = EPOLLIN | EPOLLOUT | EPOLLONESHOT | EPOLLRDHUP | EPOLLET;
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_MOD, descriptor, &event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::clear() {
|
||||||
|
epoll_ctl(ePoll.getDescriptor(), EPOLL_CTL_DEL, descriptor, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::shutdown() {
|
||||||
|
Log (LOG_DEBUG_2) << "Shutdown requested on socket " << descriptor << ".";
|
||||||
|
shutDown = true;
|
||||||
|
enable(false);
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
184
Socket.h
Normal file
184
Socket.h
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
#ifndef __Socket_h__
|
||||||
|
#define __Socket_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Object.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class EPoll;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Socket
|
||||||
|
///
|
||||||
|
/// The core component to managing a socket.
|
||||||
|
///
|
||||||
|
/// Hooks into the EPoll through the registration and unregistration process and provides a
|
||||||
|
/// communication socket of the specified protocol type. This object provides for all receiving
|
||||||
|
/// data threading through use of the EPoll object and also provides buffering for output data
|
||||||
|
/// requests to the socket.
|
||||||
|
///
|
||||||
|
/// A program using a socket object can request to open a socket (file or network or whatever) and
|
||||||
|
/// communicate through the streambuffer interface of the socket object.
|
||||||
|
///
|
||||||
|
/// The socket side of the Socket accepts EPOLLIN event and will maintain the data in a buffer
|
||||||
|
/// for the stream readers to read. A onDataReceived event is then sent with the data received in
|
||||||
|
/// the buffer that can be read through the stream.
|
||||||
|
///
|
||||||
|
/// When writing to the stream the data is written into a buffer and a EPOLLOUT is scheduled. Upon
|
||||||
|
/// receiving the EPOLLOUT event then the buffer is written to the socket output.
|
||||||
|
///
|
||||||
|
|
||||||
|
class Socket : public std::streambuf,
|
||||||
|
public core::Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Socket(EPoll &ePoll);
|
||||||
|
~Socket();
|
||||||
|
|
||||||
|
void setDescriptor(int descriptor); ///<Set the descriptor for the socket.
|
||||||
|
|
||||||
|
int getDescriptor(); ///< Get the descriptor for the socket.
|
||||||
|
|
||||||
|
class {
|
||||||
|
int value;
|
||||||
|
|
||||||
|
public:
|
||||||
|
int & operator = (const int &i) { return value = i; }
|
||||||
|
operator int () const { return value; }
|
||||||
|
|
||||||
|
} bufferSize; ////> The descriptor to monitor for this socket.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The event received from epoll is sent through the eventReceived
|
||||||
|
/// method which will parse the event and call the read and write
|
||||||
|
/// callbacks on the socket.
|
||||||
|
///
|
||||||
|
/// This method is called by the BMAEPoll object and should not be called
|
||||||
|
/// from any user extended classes unless an epoll event is being
|
||||||
|
/// simulated.
|
||||||
|
///
|
||||||
|
|
||||||
|
void eventReceived(struct epoll_event event); ///< Parse epoll event and call specified callbacks.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Write data to the socket.
|
||||||
|
///
|
||||||
|
|
||||||
|
void write(std::string data);
|
||||||
|
void write(char *buffer, int length);
|
||||||
|
|
||||||
|
void output(std::stringstream &out);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The onRegistered method is called whenever the socket is registered with
|
||||||
|
/// ePoll and socket communcation events can be started.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void onRegistered(); ///< Called when the socket has finished registering with the epoll processing.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The onUnregistered method is called whenever the socket is unregistered with
|
||||||
|
/// ePoll and socket communcation events will be stopped. The default method will
|
||||||
|
/// close the socket and clean up the connection. If this is overridden by an
|
||||||
|
/// extended object then the object should call this method to clean the socket up.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void onUnregistered(); ///< Called when the socket has finished unregistering for the epoll processing.
|
||||||
|
|
||||||
|
void enable(bool mode); ///< Enable the socket to read or write based upon buffer.
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
EPoll &ePoll; // The EPoll control object.
|
||||||
|
|
||||||
|
bool shutDown = false;
|
||||||
|
|
||||||
|
void setBufferSize(int length);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The onConnected method is called when the socket is ready to communicate.
|
||||||
|
/// Writing to the socket can begin on this call to initiate a contact with the
|
||||||
|
/// remote device.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void onConnected(); ///< Called when socket is open and ready to communicate.
|
||||||
|
|
||||||
|
virtual void onTLSInit();
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
|
// virtual void onDisconnected(); ///< Called when socket is closing and no longer ready to communicate.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The onDataReceived method is called when the socket has received an event from
|
||||||
|
/// epoll and there is data ready to be read from the socket. The default handler
|
||||||
|
/// will pull the data and put it into the streambuf for the socket. EPOLLIN
|
||||||
|
///
|
||||||
|
/// @param data the data that has been received from the socket.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void onDataReceived(std::string data) = 0; ///< Called when data is received from the socket.
|
||||||
|
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// receiveData will read the data from the socket and place it in the socket buffer.
|
||||||
|
/// TLS layer overrides this to be able to read from SSL.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void receiveData(char *buffer, int bufferLength);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int descriptor = -1;
|
||||||
|
std::mutex lock;
|
||||||
|
|
||||||
|
struct epoll_event event; // Event selection construction structure.
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// These are used to schedule the socket activity.
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
void setRead(); ///< Queue a request to read from this socket.
|
||||||
|
void setWrite(); ///< Queue a request to write to this socket.
|
||||||
|
void setReadWrite();
|
||||||
|
void resetRead();
|
||||||
|
void resetWrite();;
|
||||||
|
void resetReadWrite(int x);
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
// the writeSocket is called when epoll has received a write request for a socket.
|
||||||
|
// Writing data to this socket is queued in the streambuf and permission is requested
|
||||||
|
// to write to the socket. This routine handles the writing of the streambuf data
|
||||||
|
// buffer to the socket.
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void writeSocket();
|
||||||
|
|
||||||
|
// int_type underflow();
|
||||||
|
// int_type uflow();
|
||||||
|
// int_type pbackfail(int_type ch);
|
||||||
|
// streamsize showmanyc();
|
||||||
|
|
||||||
|
char *buffer; // This is a pointer to the managed buffer space.
|
||||||
|
int length; // This is the length of the buffer.
|
||||||
|
|
||||||
|
// const char * const begin_;
|
||||||
|
// const char * const end_;
|
||||||
|
// const char * const current_;
|
||||||
|
|
||||||
|
std::queue<std::string> fifo;
|
||||||
|
|
||||||
|
bool active = false;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
88
TCPServerSocket.cpp
Normal file
88
TCPServerSocket.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include "TCPServerSocket.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
#include "Session.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
TCPServerSocket::TCPServerSocket(EPoll &ePoll, std::string url, short int port) : TCPSocket(ePoll) {
|
||||||
|
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
|
||||||
|
struct hostent *hp = gethostbyname(url.c_str());
|
||||||
|
|
||||||
|
memcpy((void *)&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
|
||||||
|
|
||||||
|
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||||
|
|
||||||
|
int yes = 1;
|
||||||
|
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
||||||
|
|
||||||
|
if(bind(getDescriptor(), (struct sockaddr *)&addr, sizeof(addr)) < 0)
|
||||||
|
throw Exception("Error on bind to socket");
|
||||||
|
|
||||||
|
if(listen(getDescriptor(), 10) < 0)
|
||||||
|
throw Exception("Error on listen to socket");
|
||||||
|
|
||||||
|
ePoll.registerSocket(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
TCPServerSocket::~TCPServerSocket() {
|
||||||
|
close(getDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
|
void TCPServerSocket::init() {}
|
||||||
|
|
||||||
|
void TCPServerSocket::onDataReceived(std::string data) {
|
||||||
|
|
||||||
|
Log(LOG_DEBUG_2) << "Connection request on socket " << getDescriptor() << ".";
|
||||||
|
|
||||||
|
Session *session = accept();
|
||||||
|
sessions.push_back(session);
|
||||||
|
}
|
||||||
|
|
||||||
|
Session * TCPServerSocket::accept() {
|
||||||
|
|
||||||
|
Session *session = getSocketAccept();
|
||||||
|
session->setDescriptor(::accept(getDescriptor(), (struct sockaddr *)&session->ipAddress.address, &session->ipAddress.addressLength));
|
||||||
|
ePoll.registerSocket(session);
|
||||||
|
|
||||||
|
Log(LOG_DEBUG_2) << "Session started on socket " << session->getDescriptor() << ".";
|
||||||
|
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
Session * TCPServerSocket::getSocketAccept() {
|
||||||
|
return new Session(ePoll, *this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int TCPServerSocket::processCommand(std::string command, Session *session) {
|
||||||
|
|
||||||
|
int sequence = 0;
|
||||||
|
|
||||||
|
for(auto *sessionx : sessions) {
|
||||||
|
session->out << "|" << ++sequence;
|
||||||
|
sessionx->output(session);
|
||||||
|
session->out << "|" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
session->send();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TCPServerSocket::removeFromSessionList(Session *session) {
|
||||||
|
std::vector<Session *>::iterator cursor;
|
||||||
|
for(cursor = sessions.begin(); cursor < sessions.end(); ++cursor)
|
||||||
|
if(*cursor == session)
|
||||||
|
sessions.erase(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TCPServerSocket::sessionErrorHandler(std::string errorString, Session *session) {
|
||||||
|
throw Exception(errorString);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
104
TCPServerSocket.h
Normal file
104
TCPServerSocket.h
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#ifndef __TCPServerSocket_h__
|
||||||
|
#define __TCPServerSocket_h__
|
||||||
|
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "TCPSocket.h"
|
||||||
|
#include "Command.h"
|
||||||
|
#include "CommandList.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// TCPServerSocket
|
||||||
|
///
|
||||||
|
/// Manage a socket connection as a TCP server type. Connections to the socket are processed through
|
||||||
|
/// the accept functionality.
|
||||||
|
///
|
||||||
|
/// A list of connections is maintained in a vector object.
|
||||||
|
///
|
||||||
|
/// This object extends the BMACommand object as well so it can be added to a Console object and
|
||||||
|
/// process commands to display status information.
|
||||||
|
///
|
||||||
|
|
||||||
|
class TCPServerSocket : public TCPSocket, public Command {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The constructor for the BMATCPSocket object.
|
||||||
|
///
|
||||||
|
/// @param ePoll the EPoll instance that manages the socket.
|
||||||
|
/// @param url the IP address for the socket to receive connection requests.
|
||||||
|
/// @param port the port number that the socket will listen on.
|
||||||
|
/// @param commandName the name of the command used to invoke the status display for this object.
|
||||||
|
/// @return the instance of the BMATCPServerSocket.
|
||||||
|
|
||||||
|
TCPServerSocket(EPoll &ePoll, std::string url, short int port);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The destructor for this object.
|
||||||
|
///
|
||||||
|
|
||||||
|
~TCPServerSocket();
|
||||||
|
|
||||||
|
void removeFromSessionList(Session *session);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The list of sessions that are currently open and being maintained by this object.
|
||||||
|
///
|
||||||
|
|
||||||
|
std::vector<Session *> sessions;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The commands object is a CommandList and is used to store Command objects to be
|
||||||
|
/// parsed and run as data comes into the session.
|
||||||
|
///
|
||||||
|
|
||||||
|
CommandList commands;
|
||||||
|
|
||||||
|
virtual void sessionErrorHandler(std::string errorString, Session *session);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void init();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// getSocketAccept is designed to allow a polymorphic extension of this object to
|
||||||
|
/// return a type of object that extends the definition of the server socket.
|
||||||
|
/// Returning the appropriate session object that extends from BMASession provides
|
||||||
|
/// the mechanism where the server can select the protocol dialog for the desired
|
||||||
|
/// service.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual Session * getSocketAccept();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Override the virtual dataReceived since for the server these
|
||||||
|
/// are requests to accept the new connection socket.
|
||||||
|
/// No data is to be read or written when this method is called. It is the response to
|
||||||
|
/// the fact that a new connection is coming into the system
|
||||||
|
///
|
||||||
|
/// @param data the pointer to the buffer containing the received data.
|
||||||
|
/// @param length the length of the associated data buffer.
|
||||||
|
///
|
||||||
|
|
||||||
|
void onDataReceived(std::string data) override;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// This method is called when the Command associated with this object is requested
|
||||||
|
/// because a user has typed in the associated command name on a command entry line.
|
||||||
|
///
|
||||||
|
/// @param the session object to write the output to.
|
||||||
|
///
|
||||||
|
|
||||||
|
int processCommand(std::string command, Session *session) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Session * accept();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
24
TCPSocket.cpp
Normal file
24
TCPSocket.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "TCPSocket.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
TCPSocket::TCPSocket(EPoll &ePoll) : Socket(ePoll) {}
|
||||||
|
|
||||||
|
TCPSocket::~TCPSocket() {}
|
||||||
|
|
||||||
|
void TCPSocket::connect(IPAddress &address) {
|
||||||
|
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||||
|
if(::connect(getDescriptor(), (struct sockaddr *)&address.address, address.addressLength) == -1)
|
||||||
|
throw Exception("Error on connect to TCP socket.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TCPSocket::output(std::stringstream &out) {
|
||||||
|
out << "|" << ipAddress.getClientAddressAndPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
44
TCPSocket.h
Normal file
44
TCPSocket.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef __TCPSocket_h__
|
||||||
|
#define __TCPSocket_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "IPAddress.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// TCPSocket
|
||||||
|
///
|
||||||
|
/// Provides a network TCP socket.
|
||||||
|
///
|
||||||
|
/// For accessing TCP network functions use this object. The connection oriented nature of TCP
|
||||||
|
/// provides a single client persistent connection with data error correction and a durable
|
||||||
|
/// synchronous data connection.
|
||||||
|
///
|
||||||
|
|
||||||
|
class TCPSocket : public Socket {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
TCPSocket(EPoll &ePoll);
|
||||||
|
~TCPSocket();
|
||||||
|
|
||||||
|
void connect(IPAddress &address);
|
||||||
|
|
||||||
|
IPAddress ipAddress;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The output method is called by a socket session (BMASession) and
|
||||||
|
/// will output the detail information for the client socket. When extending
|
||||||
|
/// BMATCPSocket or BMASession you can override the method to add attributes
|
||||||
|
/// to the list.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void output(std::stringstream &out);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
66
TLSServerSocket.cpp
Normal file
66
TLSServerSocket.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "TLSServerSocket.h"
|
||||||
|
#include "TLSSession.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
#include "Session.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
static pthread_mutex_t *lockarray;
|
||||||
|
|
||||||
|
//static void lock_callback(int mode, int type, const char *file, int line) {
|
||||||
|
// if(mode & CRYPTO_LOCK)
|
||||||
|
// pthread_mutex_lock(&(lockarray[type]));
|
||||||
|
// else
|
||||||
|
// pthread_mutex_unlock(&(lockarray[type]));
|
||||||
|
//}
|
||||||
|
|
||||||
|
TLSServerSocket::TLSServerSocket(EPoll &ePoll, std::string url, short int port) : TCPServerSocket(ePoll, url, port) {
|
||||||
|
tlsServerInit();
|
||||||
|
// TODO: Convert to use core::Exception object.
|
||||||
|
if(!(ctx = SSL_CTX_new(SSLv23_server_method())))
|
||||||
|
throw std::string("Error while setting server method SSLv23.");
|
||||||
|
SSL_CTX_set_mode(ctx, SSL_MODE_RELEASE_BUFFERS | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
||||||
|
SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET);
|
||||||
|
SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_SERVER);
|
||||||
|
// SSL_CTX_set_generate_session_id(ctx, generate_session_id);
|
||||||
|
SSL_CTX_set_cipher_list(ctx, "ECDH-ECDSA-AES256-GCM-SHA384:DHE-DSS-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA256:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA");
|
||||||
|
if(SSL_CTX_use_certificate_file(ctx, sip_cert, SSL_FILETYPE_PEM) <= 0)
|
||||||
|
throw Exception("Error looking up certificate.");
|
||||||
|
if(SSL_CTX_use_PrivateKey_file(ctx, sip_key, SSL_FILETYPE_PEM) < 0)
|
||||||
|
throw Exception("Error with private key.");
|
||||||
|
if(SSL_CTX_check_private_key(ctx) != 1)
|
||||||
|
throw Exception("Private key does not match certificate.");
|
||||||
|
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL);
|
||||||
|
SSL_CTX_set_verify_depth(ctx, 1);
|
||||||
|
if(!SSL_CTX_load_verify_locations(ctx, sip_cacert, NULL))
|
||||||
|
throw Exception("Cannot verify locations.");
|
||||||
|
SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(sip_cacert));
|
||||||
|
Log(LOG_DEBUG_1) << "Server key authenticated.";
|
||||||
|
}
|
||||||
|
|
||||||
|
TLSServerSocket::~TLSServerSocket() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TLSServerSocket::tlsServerInit() {
|
||||||
|
SSL_library_init();
|
||||||
|
SSL_load_error_strings();
|
||||||
|
|
||||||
|
lockarray = (pthread_mutex_t *)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
|
||||||
|
for(int i = 0; i < CRYPTO_num_locks(); ++i)
|
||||||
|
pthread_mutex_init(&(lockarray[i]), NULL);
|
||||||
|
|
||||||
|
CRYPTO_set_id_callback((unsigned long (*)())thread_id);
|
||||||
|
CRYPTO_set_locking_callback((void ()(int, int, const char *, int))lock_callback);
|
||||||
|
|
||||||
|
SSLeay_add_ssl_algorithms();
|
||||||
|
RAND_load_file("/dev/hwrng", 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
Session * TLSServerSocket::getSocketAccept() {
|
||||||
|
Session *session = new TLSSession(ePoll, *this);
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
TLSServerSocket.h
Normal file
60
TLSServerSocket.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#ifndef TLSServerSocket_h__
|
||||||
|
#define TLSServerSocket_h__
|
||||||
|
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "TCPServerSocket.h"
|
||||||
|
#include "Command.h"
|
||||||
|
#include "Session.h"
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
#include <openssl/rand.h>
|
||||||
|
#include <openssl/err.h>
|
||||||
|
|
||||||
|
// Global values used by all TLS functions for this server socket.
|
||||||
|
//
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// TLSServerSocket
|
||||||
|
///
|
||||||
|
/// Manage a socket connection as a TLS server type. Connections to the socket are processed through
|
||||||
|
/// the accept functionality.
|
||||||
|
///
|
||||||
|
|
||||||
|
class TLSServerSocket : public TCPServerSocket {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The constructor for the BMATLSSocket object.
|
||||||
|
///
|
||||||
|
/// @param ePoll the BMAEPoll instance that manages the socket.
|
||||||
|
/// @param url the IP address for the socket to receive connection requests.
|
||||||
|
/// @param port the port number that the socket will listen on.
|
||||||
|
/// @param commandName the name of the command used to invoke the status display for this object.
|
||||||
|
/// @return the instance of the BMATLSServerSocket.
|
||||||
|
|
||||||
|
TLSServerSocket(EPoll &ePoll, std::string url, short int port);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The destructor for this object.
|
||||||
|
///
|
||||||
|
|
||||||
|
~TLSServerSocket();
|
||||||
|
|
||||||
|
SSL_CTX *ctx;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Session * getSocketAccept() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void tlsServerInit();
|
||||||
|
|
||||||
|
char *sip_cacert = (char *)"/home/barant/testkeys/certs/pbxca.crt";
|
||||||
|
char *sip_cert = (char *)"/home/barant/testkeys/certs/pbxserver.crt";
|
||||||
|
char *sip_key = (char *)"/home/barant/testkeys/certs/pbxserver.key";
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
127
TLSSession.cpp
Normal file
127
TLSSession.cpp
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
#include "TLSSession.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
#include <openssl/rand.h>
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
static int generate_session_id(const SSL *ssl, unsigned char *id, unsigned int *id_len) {
|
||||||
|
char *session_id_prefix = (char *)"BARANT";
|
||||||
|
unsigned int count = 0;
|
||||||
|
Log(LOG_DEBUG_3) << "Generating unique session id.";
|
||||||
|
do {
|
||||||
|
RAND_bytes(id, *id_len);
|
||||||
|
memcpy(id, session_id_prefix, (strlen(session_id_prefix) < *id_len));
|
||||||
|
} while(SSL_has_matching_session_id(ssl, id, *id_len) && (++count < 10));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handshake_complete(const SSL *ssl, int where, int ret) {
|
||||||
|
Log(LOG_DEBUG_3) << "==>" << SSL_state_string_long(ssl) << "<==";
|
||||||
|
if(where & SSL_CB_HANDSHAKE_DONE) {
|
||||||
|
X509 *ssl_client_cert = SSL_get_peer_certificate(ssl);
|
||||||
|
if(!ssl_client_cert)
|
||||||
|
throw std::string("Unable to get peer certificate.");
|
||||||
|
X509_free(ssl_client_cert);
|
||||||
|
if(SSL_get_verify_result(ssl) != X509_V_OK)
|
||||||
|
throw std::string("Certificate verification failed.");
|
||||||
|
Log(LOG_DEBUG_3) << "Certificate verified successfully.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Log(LOG_DEBUG_3) << "No client certificate.";
|
||||||
|
}
|
||||||
|
|
||||||
|
TLSSession::TLSSession(EPoll &ePoll, TLSServerSocket &server) : Session(ePoll, server) {}
|
||||||
|
|
||||||
|
void TLSSession::init() {
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
Log(LOG_DEBUG_3) << "TLS socket initializing...";
|
||||||
|
|
||||||
|
fcntl(getDescriptor(), F_SETFL, fcntl(getDescriptor(), F_GETFL, 0) | O_NONBLOCK);
|
||||||
|
|
||||||
|
if(!(ssl = SSL_new(((core::TLSServerSocket &)server).ctx)))
|
||||||
|
throw std::string("Error creating new TLS socket.");
|
||||||
|
|
||||||
|
SSL_set_info_callback(ssl, handshake_complete);
|
||||||
|
|
||||||
|
if((ret = SSL_set_fd(ssl, getDescriptor())) == 0)
|
||||||
|
throw std::string("Error setting TLS socket descriptor.");
|
||||||
|
|
||||||
|
if(!SSL_set_generate_session_id(ssl, generate_session_id))
|
||||||
|
throw std::string("Error setting session identifier callback.");
|
||||||
|
|
||||||
|
switch (SSL_get_error(ssl, SSL_accept(ssl))) {
|
||||||
|
case SSL_ERROR_SSL:
|
||||||
|
Log(LOG_DEBUG_3) << "ERROR_SSL on ssl_accept. errno=" << errno;
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_WANT_READ:
|
||||||
|
Log(LOG_DEBUG_3) << "ERROR_WANT_READ on ssl_accept.";
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_WANT_WRITE:
|
||||||
|
Log(LOG_DEBUG_3) << "ERROR_WANT_WRITE on ssl_accept.";
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_SYSCALL:
|
||||||
|
Log(LOG_DEBUG_3) << "ERROR_SYSCALL on ssl_accept. errno=" << errno;
|
||||||
|
shutdown();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log(LOG_DEBUG_3) << "Unknown ERROR on ssl_accept.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TLSSession::~TLSSession() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TLSSession::protocol(std::string data) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TLSSession::receiveData(char *buffer, int bufferLength) {
|
||||||
|
|
||||||
|
if(!initialized)
|
||||||
|
init();
|
||||||
|
|
||||||
|
int len;
|
||||||
|
// int error = -1;
|
||||||
|
//
|
||||||
|
std::cout << "receiveData TLS" << std::endl;
|
||||||
|
|
||||||
|
if((len = ::SSL_read(ssl, buffer, bufferLength)) >= 0) {
|
||||||
|
std::cout << "receiveData TLS...len=" << len << ":" << buffer << std::endl;
|
||||||
|
onDataReceived(std::string(buffer, len));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch (SSL_get_error(ssl, len)) {
|
||||||
|
case SSL_ERROR_SSL:
|
||||||
|
Log(LOG_DEBUG_3) << "ERROR_SSL on ssl_read. error=" << errno;
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_WANT_READ:
|
||||||
|
Log(LOG_DEBUG_3) << "ERROR_WANT_READ on ssl_read.";
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_WANT_WRITE:
|
||||||
|
Log(LOG_DEBUG_3) << "ERROR_WANT_WRITE on ssl_read.";
|
||||||
|
break;
|
||||||
|
case SSL_ERROR_SYSCALL:
|
||||||
|
Log(LOG_DEBUG_3) << "ERROR_SYSCALL on ssl_read. errno=" << errno;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log(LOG_DEBUG_3) << "Unknown ERROR on ssl_read.";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TLSSession::output(std::stringstream &out) {
|
||||||
|
out << "|" << ipAddress.getClientAddressAndPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
53
TLSSession.h
Normal file
53
TLSSession.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef __TLSSession_h__
|
||||||
|
#define __TLSSession_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Session.h"
|
||||||
|
#include "TLSServerSocket.h"
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class TLSServerSocket;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// TLSSession
|
||||||
|
///
|
||||||
|
/// Provides a network TLS socket.
|
||||||
|
///
|
||||||
|
/// For accessing TLS network functions use this object. The connection oriented nature of TLS
|
||||||
|
/// provides a single client persistent connection with data error correction and a durable
|
||||||
|
/// synchronous data connection.
|
||||||
|
///
|
||||||
|
|
||||||
|
class TLSSession : public Session {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
TLSSession(EPoll &ePoll, TLSServerSocket &server);
|
||||||
|
~TLSSession();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The output method is called by a socket session (Session) and
|
||||||
|
/// will output the detail information for the client socket. When extending
|
||||||
|
/// TLSSocket or Session you can override the method to add attributes
|
||||||
|
/// to the list.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void output(std::stringstream &out);
|
||||||
|
virtual void protocol(std::string data) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void init() override;
|
||||||
|
void receiveData(char *buffer, int bufferLength) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool initialized = false;
|
||||||
|
// TLSServerSocket &server;
|
||||||
|
SSL *ssl;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
56
TerminalSession.cpp
Normal file
56
TerminalSession.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "TerminalSession.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
TerminalSession::TerminalSession(EPoll &ePoll, TCPServerSocket &server) : Session(ePoll, server) {
|
||||||
|
}
|
||||||
|
|
||||||
|
TerminalSession::~TerminalSession() {
|
||||||
|
}
|
||||||
|
|
||||||
|
int TerminalSession::getLines() {
|
||||||
|
struct winsize size;
|
||||||
|
ioctl(getDescriptor(), TIOCGWINSZ, &size);
|
||||||
|
return size.ws_row;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::clear() {
|
||||||
|
out << esc << "[2J";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::clearEOL() {
|
||||||
|
out << esc << "[2K";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::setCursorLocation(int x, int y) {
|
||||||
|
out << esc << "[" << x << ";" << y << "H";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::setColor(int color) {
|
||||||
|
out << esc << "[" << color << "m";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::setBackColor(int color) {
|
||||||
|
out << esc << "[" << color << "m";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::saveCursor() {
|
||||||
|
out << esc << "7";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::restoreCursor() {
|
||||||
|
out << esc << "8";
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::NextLine(int lines) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::PreviousLine(int lines) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void TerminalSession::scrollArea(int start, int end) {
|
||||||
|
out << esc << "[" << start << ";" << end << "r";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
52
TerminalSession.h
Normal file
52
TerminalSession.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#ifndef __Terminal_h__
|
||||||
|
#define __Terminal_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Session.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
static const int FG_BLACK = 30;
|
||||||
|
static const int FG_RED = 31;
|
||||||
|
static const int FG_GREEN = 32;
|
||||||
|
static const int FG_YELLOW = 33;
|
||||||
|
static const int FG_BLUE = 34;
|
||||||
|
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;
|
||||||
|
static const int BG_YELLOW = 43;
|
||||||
|
static const int BG_BLUE = 44;
|
||||||
|
static const int BG_MAGENTA = 45;
|
||||||
|
static const int BG_CYAN = 46;
|
||||||
|
static const int BG_WHITE = 47;
|
||||||
|
|
||||||
|
static const char esc = 0x1b;
|
||||||
|
|
||||||
|
class TerminalSession : public Session {
|
||||||
|
|
||||||
|
public:
|
||||||
|
TerminalSession(EPoll &ePoll, TCPServerSocket &server);
|
||||||
|
~TerminalSession();
|
||||||
|
|
||||||
|
int getLines();
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
void clearEOL();
|
||||||
|
void setCursorLocation(int x, int y);
|
||||||
|
void setColor(int color);
|
||||||
|
void setBackColor(int color);
|
||||||
|
void saveCursor();
|
||||||
|
void restoreCursor();
|
||||||
|
void NextLine(int lines);
|
||||||
|
void PreviousLine(int lines);
|
||||||
|
void scrollArea(int start, int end);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
70
Thread.cpp
Normal file
70
Thread.cpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include "Thread.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
Thread::Thread(EPoll &ePoll) : ePoll(ePoll) {}
|
||||||
|
|
||||||
|
Thread::~Thread() {}
|
||||||
|
|
||||||
|
void Thread::start() {
|
||||||
|
_thread = new std::thread(&Thread::run, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::join() {
|
||||||
|
_thread->join();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Thread::getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t Thread::getThreadId() {
|
||||||
|
return threadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Thread::getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thread::output(Session *session) {
|
||||||
|
session->out << "|" << getThreadId();
|
||||||
|
session->out << "|" << getStatus();
|
||||||
|
session->out << "|" << getCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Thread::run() {
|
||||||
|
|
||||||
|
threadId = syscall(SYS_gettid);
|
||||||
|
|
||||||
|
Log(LOG_DEBUG_1) << "Thread started with thread id " << threadId << ".";
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
struct epoll_event events[50];
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
|
||||||
|
if(ePoll.isStopping())
|
||||||
|
break;
|
||||||
|
|
||||||
|
status = "WAITING";
|
||||||
|
int rc = epoll_wait(ePoll.getDescriptor(), events, 50, -1);
|
||||||
|
status = "RUNNING";
|
||||||
|
|
||||||
|
if(rc < 0) {
|
||||||
|
// TODO: Make log entry indicating status received and ignore for now.
|
||||||
|
} else if(rc == 0) {
|
||||||
|
break;
|
||||||
|
} else if(rc > 0) {
|
||||||
|
for(int ix = 0; ix < rc; ++ix) {
|
||||||
|
++count;
|
||||||
|
ePoll.eventReceived(events[ix]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
51
Thread.h
Normal file
51
Thread.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#ifndef __Thread_h__
|
||||||
|
#define __Thread_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "Object.h"
|
||||||
|
#include "Session.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class EPoll;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Thread
|
||||||
|
///
|
||||||
|
/// This thread object is designed to be the thread processor for the EPoll object. It wraps the thread
|
||||||
|
/// object to allow maintaining a status value for monitoring the thread activity. EPoll will instantiate
|
||||||
|
/// a Thread object for each thread specified in the EPoll's start method.
|
||||||
|
///
|
||||||
|
|
||||||
|
class Thread : public Object {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Thread(EPoll &ePoll);
|
||||||
|
~Thread();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Start the thread object. This will cause the epoll scheduler to commence reading the epoll queue.
|
||||||
|
///
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void join();
|
||||||
|
std::string getStatus();
|
||||||
|
pid_t getThreadId();
|
||||||
|
int getCount();
|
||||||
|
void output(Session *session);
|
||||||
|
|
||||||
|
private:
|
||||||
|
EPoll &ePoll; // The EPoll control object.
|
||||||
|
std::string status;
|
||||||
|
int count;
|
||||||
|
std::thread *_thread;
|
||||||
|
void print_thread_start_log();
|
||||||
|
pid_t threadId;
|
||||||
|
void run();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
62
Timer.cpp
Normal file
62
Timer.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include "Timer.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
Timer::Timer(EPoll &ePoll, double delay = 0.0f) : Socket(ePoll) {
|
||||||
|
setDescriptor(timerfd_create(CLOCK_REALTIME, 0));
|
||||||
|
ePoll.registerSocket(this);
|
||||||
|
setTimer(delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer::~Timer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::setTimer(double delay) {
|
||||||
|
|
||||||
|
double integer;
|
||||||
|
double fraction;
|
||||||
|
struct itimerspec timer;
|
||||||
|
|
||||||
|
delayValue = delay;
|
||||||
|
|
||||||
|
timer.it_interval.tv_sec = 0;
|
||||||
|
timer.it_interval.tv_nsec = 0;
|
||||||
|
|
||||||
|
fraction = modf(delay, &integer);
|
||||||
|
|
||||||
|
timer.it_value.tv_sec = (int)integer;
|
||||||
|
timer.it_value.tv_nsec = (int)(fraction * 1000000000);
|
||||||
|
|
||||||
|
timerfd_settime(getDescriptor(), 0, &timer, NULL);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::clearTimer() {
|
||||||
|
|
||||||
|
struct itimerspec timer;
|
||||||
|
|
||||||
|
timer.it_interval.tv_sec = 0;
|
||||||
|
timer.it_interval.tv_nsec = 0;
|
||||||
|
timer.it_value.tv_sec = 0;
|
||||||
|
timer.it_value.tv_nsec = 0;
|
||||||
|
|
||||||
|
timerfd_settime(getDescriptor(), 0, &timer, NULL);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
double Timer::getElapsed() {
|
||||||
|
struct itimerspec timer;
|
||||||
|
timerfd_gettime(getDescriptor(), &timer);
|
||||||
|
double toTimeout = (double)((timer.it_value.tv_sec * 1000000000L) + timer.it_value.tv_nsec) / 1000000000L;
|
||||||
|
return delayValue - toTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::onDataReceived(std::string data) {
|
||||||
|
onTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
double Timer::getEpoch() {
|
||||||
|
return (double)std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count() /1000000000L;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
66
Timer.h
Normal file
66
Timer.h
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#ifndef __Timer_h__
|
||||||
|
#define __Timer_h__
|
||||||
|
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Timer
|
||||||
|
///
|
||||||
|
/// Set and trigger callback upon specified timeout.
|
||||||
|
///
|
||||||
|
/// The Timer is used to establish a timer using the timer socket
|
||||||
|
/// interface. It cannot be instantiated directly but must be extended.
|
||||||
|
///
|
||||||
|
|
||||||
|
class Timer : Socket {
|
||||||
|
|
||||||
|
public:
|
||||||
|
Timer(EPoll &ePoll);
|
||||||
|
Timer(EPoll &ePoll, double delay);
|
||||||
|
~Timer();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use the setTimer() method to set the time out value for timer. Setting the timer
|
||||||
|
/// also starts the timer countdown. The clearTimer() method can be used to reset
|
||||||
|
/// the timer without triggering the onTimeout() callback.
|
||||||
|
///
|
||||||
|
/// @param delay the amount of time in seconds to wait before trigering the onTimeout function.
|
||||||
|
///
|
||||||
|
|
||||||
|
void setTimer(double delay);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use the clearTimer() to unset the timer and return the timer to an idle state.
|
||||||
|
///
|
||||||
|
|
||||||
|
void clearTimer();
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use the getElapsed() method to obtain the amount of time that has elapsed since
|
||||||
|
/// the timer was set.
|
||||||
|
///
|
||||||
|
|
||||||
|
double getElapsed();
|
||||||
|
|
||||||
|
double getEpoch();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
///
|
||||||
|
/// This method is called when the time out occurs.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void onTimeout() = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onDataReceived(std::string data) override;
|
||||||
|
double delayValue;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
61
UDPServerSocket.cpp
Normal file
61
UDPServerSocket.cpp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "UDPServerSocket.h"
|
||||||
|
#include "EPoll.h"
|
||||||
|
#include "Session.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
UDPServerSocket::UDPServerSocket(EPoll &ePoll, std::string url, short int port, std::string commandName) : UDPSocket(ePoll) {
|
||||||
|
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_port = htons(port);
|
||||||
|
|
||||||
|
struct hostent *hp = gethostbyname(url.c_str());
|
||||||
|
|
||||||
|
memcpy((void *)&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
|
||||||
|
|
||||||
|
setDescriptor(socket(AF_INET, SOCK_STREAM, 0));
|
||||||
|
|
||||||
|
int yes = 1;
|
||||||
|
setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int));
|
||||||
|
|
||||||
|
bind(getDescriptor(), (struct sockaddr *)&addr, sizeof(addr));
|
||||||
|
|
||||||
|
listen(getDescriptor(), 10);
|
||||||
|
|
||||||
|
ePoll.registerSocket(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UDPServerSocket::~UDPServerSocket() {
|
||||||
|
close(getDescriptor());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UDPServerSocket::onDataReceived(std::string data) {
|
||||||
|
|
||||||
|
// TODO: Here we read the client address and establish a session object or
|
||||||
|
// or find it in the vector if it was already in use and then
|
||||||
|
// send the data to the session.
|
||||||
|
//
|
||||||
|
// sessions.push_back(session);
|
||||||
|
//
|
||||||
|
// BMASession::onDataReceived(data, length);
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
int UDPServerSocket::processCommand(Session *session) {
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
int sequence = 0;
|
||||||
|
|
||||||
|
for(auto *session : sessions) {
|
||||||
|
out << "|" << ++sequence;
|
||||||
|
session->output(session);
|
||||||
|
out << "|" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
session->write(out.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
48
UDPServerSocket.h
Normal file
48
UDPServerSocket.h
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#ifndef __UDPServerSocket_h__
|
||||||
|
#define __UDPServerSocket_h__
|
||||||
|
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "UDPSocket.h"
|
||||||
|
#include "Command.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// UDPSocket
|
||||||
|
///
|
||||||
|
/// Manage a socket connection as a UDP server type. Connections to the socket are processed through
|
||||||
|
/// the session list functionality. A list of sessions is maintained in a vector object.
|
||||||
|
///
|
||||||
|
|
||||||
|
class UDPServerSocket : public UDPSocket, public Command {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UDPServerSocket(EPoll &ePoll, std::string url, short int port, std::string commandName);
|
||||||
|
~UDPServerSocket();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
// Override the virtual dataReceived since for the server these
|
||||||
|
// are requests to accept the new connection socket.
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
|
||||||
|
void onDataReceived(std::string data) override;
|
||||||
|
|
||||||
|
int processCommand(Session *session);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
// The retrieved socket connections are placed into the client vector list.
|
||||||
|
//------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
std::vector<Session *> sessions;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
9
UDPSocket.cpp
Normal file
9
UDPSocket.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "UDPSocket.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
UDPSocket::UDPSocket(EPoll &ePoll) : Socket(ePoll) {}
|
||||||
|
|
||||||
|
UDPSocket::~UDPSocket() {}
|
||||||
|
|
||||||
|
}
|
22
UDPSocket.h
Normal file
22
UDPSocket.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef UDPSocket_h__
|
||||||
|
#define UDPSocket_h__
|
||||||
|
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "Session.h"
|
||||||
|
|
||||||
|
namespace core {
|
||||||
|
|
||||||
|
class UDPSocket : public Socket {
|
||||||
|
|
||||||
|
public:
|
||||||
|
UDPSocket(EPoll &ePoll);
|
||||||
|
~UDPSocket();
|
||||||
|
|
||||||
|
// virtual int open(string address, short int port);
|
||||||
|
// virtual void write(istream data);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
15
docs/guide/BMASockets Programmer's Guide.aux
Normal file
15
docs/guide/BMASockets Programmer's Guide.aux
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
\relax
|
||||||
|
\@writefile{toc}{\contentsline {chapter}{\numberline {1}Overview}{3}}
|
||||||
|
\@writefile{lof}{\addvspace {10\p@ }}
|
||||||
|
\@writefile{lot}{\addvspace {10\p@ }}
|
||||||
|
\@writefile{toc}{\contentsline {chapter}{\numberline {2}Linux epoll Interactions}{5}}
|
||||||
|
\@writefile{lof}{\addvspace {10\p@ }}
|
||||||
|
\@writefile{lot}{\addvspace {10\p@ }}
|
||||||
|
\@writefile{toc}{\contentsline {chapter}{\numberline {3}The Core Server}{7}}
|
||||||
|
\@writefile{lof}{\addvspace {10\p@ }}
|
||||||
|
\@writefile{lot}{\addvspace {10\p@ }}
|
||||||
|
\@writefile{toc}{\contentsline {chapter}{\numberline {4}Sample Server Example}{9}}
|
||||||
|
\@writefile{lof}{\addvspace {10\p@ }}
|
||||||
|
\@writefile{lot}{\addvspace {10\p@ }}
|
||||||
|
\@writefile{toc}{\contentsline {section}{\numberline {4.1}The Server}{9}}
|
||||||
|
\@writefile{toc}{\contentsline {section}{\numberline {4.2}The Session}{11}}
|
200
docs/guide/BMASockets Programmer's Guide.log
Normal file
200
docs/guide/BMASockets Programmer's Guide.log
Normal file
@ -0,0 +1,200 @@
|
|||||||
|
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex 2018.5.16) 18 MAY 2018 02:53
|
||||||
|
entering extended mode
|
||||||
|
restricted \write18 enabled.
|
||||||
|
%&-line parsing enabled.
|
||||||
|
**"BMASockets Programmer's Guide.tex"
|
||||||
|
(./BMASockets Programmer's Guide.tex
|
||||||
|
LaTeX2e <2017-04-15>
|
||||||
|
Babel <3.18> and hyphenation patterns for 5 language(s) loaded.
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/base/book.cls
|
||||||
|
Document Class: book 2014/09/29 v1.4h Standard LaTeX document class
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/base/bk10.clo
|
||||||
|
File: bk10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
|
||||||
|
)
|
||||||
|
\c@part=\count79
|
||||||
|
\c@chapter=\count80
|
||||||
|
\c@section=\count81
|
||||||
|
\c@subsection=\count82
|
||||||
|
\c@subsubsection=\count83
|
||||||
|
\c@paragraph=\count84
|
||||||
|
\c@subparagraph=\count85
|
||||||
|
\c@figure=\count86
|
||||||
|
\c@table=\count87
|
||||||
|
\abovecaptionskip=\skip41
|
||||||
|
\belowcaptionskip=\skip42
|
||||||
|
\bibindent=\dimen102
|
||||||
|
)
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty
|
||||||
|
Package: xcolor 2016/05/11 v2.12 LaTeX color extensions (UK)
|
||||||
|
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg
|
||||||
|
File: color.cfg 2016/01/02 v1.6 sample color configuration
|
||||||
|
)
|
||||||
|
Package xcolor Info: Driver file: pdftex.def on input line 225.
|
||||||
|
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def
|
||||||
|
File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
|
||||||
|
)
|
||||||
|
Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1348.
|
||||||
|
Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1352.
|
||||||
|
Package xcolor Info: Model `RGB' extended on input line 1364.
|
||||||
|
Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1366.
|
||||||
|
Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1367.
|
||||||
|
Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1368.
|
||||||
|
Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1369.
|
||||||
|
Package xcolor Info: Model `Gray' substituted by `gray' on input line 1370.
|
||||||
|
Package xcolor Info: Model `wave' substituted by `hsb' on input line 1371.
|
||||||
|
)
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/listings/listings.sty
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty
|
||||||
|
Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
|
||||||
|
\KV@toks@=\toks14
|
||||||
|
)
|
||||||
|
\lst@mode=\count88
|
||||||
|
\lst@gtempboxa=\box26
|
||||||
|
\lst@token=\toks15
|
||||||
|
\lst@length=\count89
|
||||||
|
\lst@currlwidth=\dimen103
|
||||||
|
\lst@column=\count90
|
||||||
|
\lst@pos=\count91
|
||||||
|
\lst@lostspace=\dimen104
|
||||||
|
\lst@width=\dimen105
|
||||||
|
\lst@newlines=\count92
|
||||||
|
\lst@lineno=\count93
|
||||||
|
\lst@maxwidth=\dimen106
|
||||||
|
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/listings/lstmisc.sty
|
||||||
|
File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz)
|
||||||
|
\c@lstnumber=\count94
|
||||||
|
\lst@skipnumbers=\count95
|
||||||
|
\lst@framebox=\box27
|
||||||
|
)
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/listings/listings.cfg
|
||||||
|
File: listings.cfg 2015/06/04 1.6 listings configuration
|
||||||
|
))
|
||||||
|
Package: listings 2015/06/04 1.6 (Carsten Heinz)
|
||||||
|
|
||||||
|
(./BMASockets Programmer's Guide.aux)
|
||||||
|
\openout1 = `"BMASockets Programmer's Guide.aux"'.
|
||||||
|
|
||||||
|
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 30.
|
||||||
|
LaTeX Font Info: ... okay on input line 30.
|
||||||
|
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 30.
|
||||||
|
LaTeX Font Info: ... okay on input line 30.
|
||||||
|
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 30.
|
||||||
|
LaTeX Font Info: ... okay on input line 30.
|
||||||
|
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 30.
|
||||||
|
LaTeX Font Info: ... okay on input line 30.
|
||||||
|
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 30.
|
||||||
|
LaTeX Font Info: ... okay on input line 30.
|
||||||
|
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 30.
|
||||||
|
LaTeX Font Info: ... okay on input line 30.
|
||||||
|
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
|
||||||
|
[Loading MPS to PDF converter (version 2006.09.02).]
|
||||||
|
\scratchcounter=\count96
|
||||||
|
\scratchdimen=\dimen107
|
||||||
|
\scratchbox=\box28
|
||||||
|
\nofMPsegments=\count97
|
||||||
|
\nofMParguments=\count98
|
||||||
|
\everyMPshowfont=\toks16
|
||||||
|
\MPscratchCnt=\count99
|
||||||
|
\MPscratchDim=\dimen108
|
||||||
|
\MPnumerator=\count100
|
||||||
|
\makeMPintoPDFobject=\count101
|
||||||
|
\everyMPtoPDFconversion=\toks17
|
||||||
|
)
|
||||||
|
\c@lstlisting=\count102
|
||||||
|
(./BMASockets Programmer's Guide.toc
|
||||||
|
LaTeX Font Info: External font `cmex10' loaded for size
|
||||||
|
(Font) <7> on input line 5.
|
||||||
|
LaTeX Font Info: External font `cmex10' loaded for size
|
||||||
|
(Font) <5> on input line 5.
|
||||||
|
)
|
||||||
|
\tf@toc=\write3
|
||||||
|
\openout3 = `"BMASockets Programmer's Guide.toc"'.
|
||||||
|
|
||||||
|
[1
|
||||||
|
|
||||||
|
|
||||||
|
{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] [2
|
||||||
|
|
||||||
|
]
|
||||||
|
Chapter 1.
|
||||||
|
[3] [4
|
||||||
|
|
||||||
|
]
|
||||||
|
Chapter 2.
|
||||||
|
[5] [6
|
||||||
|
|
||||||
|
]
|
||||||
|
Chapter 3.
|
||||||
|
|
||||||
|
Overfull \hbox (1.13943pt too wide) in paragraph at lines 108--112
|
||||||
|
[]\OT1/cmr/m/n/10 The ex-tended BMASes-sion ob-ject can over-ride the on-DataRe
|
||||||
|
-ceived() method
|
||||||
|
[]
|
||||||
|
|
||||||
|
[7] [8
|
||||||
|
|
||||||
|
]
|
||||||
|
Chapter 4.
|
||||||
|
|
||||||
|
Overfull \hbox (0.16724pt too wide) in paragraph at lines 121--122
|
||||||
|
[]\OT1/cmr/m/n/10 Additionally, this server ex-am-ple pro-vides a con-sole that
|
||||||
|
is ac-ces-si-ble through
|
||||||
|
[]
|
||||||
|
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/listings/lstlang1.sty
|
||||||
|
File: lstlang1.sty 2015/06/04 1.6 listings language file
|
||||||
|
)
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/listings/lstmisc.sty
|
||||||
|
File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz)
|
||||||
|
) [9]
|
||||||
|
LaTeX Font Info: Try loading font information for OMS+cmr on input line 140.
|
||||||
|
|
||||||
|
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/base/omscmr.fd
|
||||||
|
File: omscmr.fd 2014/09/29 v2.5h Standard LaTeX font definitions
|
||||||
|
)
|
||||||
|
LaTeX Font Info: Font shape `OMS/cmr/m/n' in size <8> not available
|
||||||
|
(Font) Font shape `OMS/cmsy/m/n' tried instead on input line 140.
|
||||||
|
LaTeX Font Info: Try loading font information for OML+cmr on input line 150.
|
||||||
|
|
||||||
|
|
||||||
|
(/usr/share/texlive/texmf-dist/tex/latex/base/omlcmr.fd
|
||||||
|
File: omlcmr.fd 2014/09/29 v2.5h Standard LaTeX font definitions
|
||||||
|
)
|
||||||
|
LaTeX Font Info: Font shape `OML/cmr/m/n' in size <8> not available
|
||||||
|
(Font) Font shape `OML/cmm/m/it' tried instead on input line 150.
|
||||||
|
LaTeX Font Info: External font `cmex10' loaded for size
|
||||||
|
(Font) <8> on input line 190.
|
||||||
|
LaTeX Font Info: External font `cmex10' loaded for size
|
||||||
|
(Font) <6> on input line 190.
|
||||||
|
[10] [11] [12]
|
||||||
|
(./BMASockets Programmer's Guide.aux) )
|
||||||
|
Here is how much of TeX's memory you used:
|
||||||
|
2684 strings out of 494880
|
||||||
|
36203 string characters out of 6179601
|
||||||
|
236674 words of memory out of 5000000
|
||||||
|
6032 multiletter control sequences out of 15000+600000
|
||||||
|
8287 words of font info for 29 fonts, out of 8000000 for 9000
|
||||||
|
36 hyphenation exceptions out of 8191
|
||||||
|
30i,6n,58p,392b,1622s stack positions out of 5000i,500n,10000p,200000b,80000s
|
||||||
|
</usr/share/texlive/texmf-dist/fonts/typ
|
||||||
|
e1/public/amsfonts/cm/cmbx10.pfb></usr/share/texlive/texmf-dist/fonts/type1/pub
|
||||||
|
lic/amsfonts/cm/cmbx12.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/am
|
||||||
|
sfonts/cm/cmmi8.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/
|
||||||
|
cm/cmr10.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr5
|
||||||
|
.pfb></usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr8.pfb></u
|
||||||
|
sr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmsl10.pfb></usr/sha
|
||||||
|
re/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy8.pfb></usr/share/texl
|
||||||
|
ive/texmf-dist/fonts/type1/public/amsfonts/cm/cmti10.pfb>
|
||||||
|
Output written on "BMASockets Programmer's Guide.pdf" (12 pages, 129850 bytes).
|
||||||
|
|
||||||
|
PDF statistics:
|
||||||
|
79 PDF objects out of 1000 (max. 8388607)
|
||||||
|
55 compressed objects within 1 object stream
|
||||||
|
0 named destinations out of 1000 (max. 500000)
|
||||||
|
1 words of extra memory for PDF output out of 10000 (max. 10000000)
|
||||||
|
|
BIN
docs/guide/BMASockets Programmer's Guide.pdf
Normal file
BIN
docs/guide/BMASockets Programmer's Guide.pdf
Normal file
Binary file not shown.
BIN
docs/guide/BMASockets Programmer's Guide.synctex.gz
Normal file
BIN
docs/guide/BMASockets Programmer's Guide.synctex.gz
Normal file
Binary file not shown.
275
docs/guide/BMASockets Programmer's Guide.tex
Normal file
275
docs/guide/BMASockets Programmer's Guide.tex
Normal file
@ -0,0 +1,275 @@
|
|||||||
|
\documentclass[10pt]{book}
|
||||||
|
\usepackage{xcolor}
|
||||||
|
\usepackage{listings}
|
||||||
|
|
||||||
|
\definecolor{mGreen}{rgb}{0,0.6,0}
|
||||||
|
\definecolor{mGray}{rgb}{0.5,0.5,0.5}
|
||||||
|
\definecolor{mPurple}{rgb}{0.58,0,0.82}
|
||||||
|
\definecolor{backgroundColour}{rgb}{0.95,0.95,0.92}
|
||||||
|
|
||||||
|
\lstdefinestyle{CStyle}{
|
||||||
|
backgroundcolor=\color{backgroundColour},
|
||||||
|
commentstyle=\color{mGreen},
|
||||||
|
keywordstyle=\color{magenta},
|
||||||
|
numberstyle=\tiny\color{mGray},
|
||||||
|
stringstyle=\color{mPurple},
|
||||||
|
basicstyle=\footnotesize,
|
||||||
|
breakatwhitespace=false,
|
||||||
|
breaklines=true,
|
||||||
|
captionpos=b,
|
||||||
|
keepspaces=true,
|
||||||
|
numbers=left,
|
||||||
|
numbersep=5pt,
|
||||||
|
showspaces=false,
|
||||||
|
showstringspaces=false,
|
||||||
|
showtabs=false,
|
||||||
|
tabsize=2,
|
||||||
|
language=C
|
||||||
|
}
|
||||||
|
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\tableofcontents
|
||||||
|
|
||||||
|
\chapter{Overview}
|
||||||
|
|
||||||
|
Welcome to BMASockets Core Server. The server core was developed to
|
||||||
|
provide a quick path to developing your server requirements on a high
|
||||||
|
performance Linux platform network. The design can be used to develop
|
||||||
|
customing gaming platforms or you can use any of the existing protocol
|
||||||
|
session handlers to implement your own compact high performance server
|
||||||
|
using existing known protocols.
|
||||||
|
|
||||||
|
The BMASockets Core Server provides existing handlers for the
|
||||||
|
following protocols:
|
||||||
|
|
||||||
|
\begin{enumerate}
|
||||||
|
\item HTTP and HTTPS
|
||||||
|
\item SIP and SIPS
|
||||||
|
\item HTTP streaming server
|
||||||
|
\item HTTP Web Sockets handler
|
||||||
|
\end{enumerate}
|
||||||
|
|
||||||
|
The focus of the design is to extend the capabilities of two core
|
||||||
|
objects to create the interface to your own implementations.
|
||||||
|
|
||||||
|
\chapter{Linux epoll Interactions}
|
||||||
|
|
||||||
|
Linux provides an set of system calls to open a socket that is used to
|
||||||
|
manage the networking requests for multiple sockets from a single
|
||||||
|
process. You can find plenty of materials on the internet on epoll and
|
||||||
|
how this function works. The Core Server is designed around the
|
||||||
|
concept of the socket (BMASocket) and the handling of accepting
|
||||||
|
connections on a binding socket and managing the individual client
|
||||||
|
sockets that are \emph{accepted}.
|
||||||
|
|
||||||
|
TCP and UDP are both supported by the Core Server. The differences in
|
||||||
|
managing these socket types is abstracted through the use of the
|
||||||
|
sessions object (BMASession). This abstract class cannot be
|
||||||
|
instantiated but is used instead to extend into a customizable session
|
||||||
|
object that will be used to manage the protocol for the connected
|
||||||
|
session. At the session level there is no difference between the
|
||||||
|
underlying socket type, whether it be UDP or TCP.
|
||||||
|
|
||||||
|
The TCP side of the fence incorporates the connection oriented design
|
||||||
|
to provide the sessions to the higher levels. Each client represents a
|
||||||
|
socket that has connected through the \emph{bind} and \emph{accept}
|
||||||
|
system call method. Conversing with a client in a TCP session returns
|
||||||
|
the appropriate data through that socket connection.
|
||||||
|
|
||||||
|
The UDP side of the fence incorporates session objects that are based
|
||||||
|
upon connectionless packets sent to a single receiving socket. The UDP
|
||||||
|
server (BMAUDPServerSocket) maintains a list of sessions which are
|
||||||
|
managed according the sending address of the packets received. Each remote
|
||||||
|
address represents a different client and interactions back to the
|
||||||
|
session are sent through the single socket to the corresponding remote
|
||||||
|
address. This provides a seamless session to the higher level
|
||||||
|
activities of the server.
|
||||||
|
|
||||||
|
The interface provided through the session appears the same regardless
|
||||||
|
of the socket type. This affords the developer the opportunity to
|
||||||
|
write UDP or TCP socket handlers with no knowledge of the those
|
||||||
|
protocols. Building a game server would be the same for either type
|
||||||
|
and both types could be enabled simultaneously.
|
||||||
|
|
||||||
|
\chapter{The Core Server}
|
||||||
|
|
||||||
|
In order to provide flexibility to the Core Server several design
|
||||||
|
factors have been put in place. Creating a new server that handles a
|
||||||
|
custom protocol requires the extension of only two objects. These are
|
||||||
|
the BMATCPServerSocket or BMAUDPServerSocket, depending on the type
|
||||||
|
desired, and the BMASession object.
|
||||||
|
|
||||||
|
When extending the BMATCPServerSocket all that is needed is to
|
||||||
|
override the getSocketAccept() method to return an extended BMASession
|
||||||
|
object. This basically tells the server to spawn a new session of a
|
||||||
|
particular type for every new connection to the bound TCP port.
|
||||||
|
|
||||||
|
The extended BMASession object can override the onDataReceived()
|
||||||
|
method to handle the incoming requests for the socket. An entire
|
||||||
|
application structure could be built upon this mechanism to handle
|
||||||
|
complex protocols with the client.
|
||||||
|
|
||||||
|
\chapter{Sample Server Example}
|
||||||
|
|
||||||
|
This chapter specifies the approach to extending and creating a customized server. This example is focusing on a server used in gaming environments. The gaming clients connect to the server to interact with other clients.
|
||||||
|
|
||||||
|
The BMA Server Core can provide all the features needed of a multiport high demand server. The implementation of epoll combined with the ability to manage job control load through the use of multiple threads provides a robust request handling environment for all socket based architectures.
|
||||||
|
|
||||||
|
As the BMAEPoll object is started it will spawn the specified number of threads which will in turn begin the socket handling functions necessary to manage all network requests in the program. The main program itself is not used but must not be allowed to return or end so it can be used to handle other non sockets related processing in the application.
|
||||||
|
|
||||||
|
Additionally, this server example provides a console that is accessible through a Telnet style server and does not currently incorporate any encryption (TLS) or login authentication. This will be changing in the future.
|
||||||
|
|
||||||
|
\section{The Server}
|
||||||
|
|
||||||
|
The server provides a few interesting features that may not be readily apparent when reading through the documentation.
|
||||||
|
|
||||||
|
Since each BMATCPServerSocket also inherits from BMACommand the server can override a routine to output data relivant to the type of server you are creating.
|
||||||
|
|
||||||
|
When creating the server you are asked to provide a command name as a parameter. The inheriting server object can then obtain a list of connected clients from a console object by typing this name in on a command line.
|
||||||
|
|
||||||
|
\begin{lstlisting}[style=CStyle]
|
||||||
|
#ifndef BMAConsoleServer_h__
|
||||||
|
#define BMAConsoleServer_h__
|
||||||
|
|
||||||
|
#include "includes"
|
||||||
|
#include "BMATCPServerSocket.h"
|
||||||
|
#include "BMACommand.h"
|
||||||
|
class BMATCPSocket;
|
||||||
|
|
||||||
|
class BMAConsoleServer : public BMATCPServerSocket {
|
||||||
|
|
||||||
|
public:
|
||||||
|
BMAConsoleServer(BMAEPoll &ePoll, std::string url, short int port);
|
||||||
|
~BMAConsoleServer();
|
||||||
|
|
||||||
|
BMASession * getSocketAccept();
|
||||||
|
|
||||||
|
void registerCommand(BMACommand &command);
|
||||||
|
|
||||||
|
int processCommand(BMASession *session) override; ///<Output the consoles array to the console.
|
||||||
|
|
||||||
|
std::vector<BMACommand *> commands;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
\end{lstlisting}
|
||||||
|
|
||||||
|
\begin{lstlisting}[style=CStyle]
|
||||||
|
#include "BMAEPoll.h"
|
||||||
|
#include "BMAConsoleServer.h"
|
||||||
|
#include "BMAConsoleSession.h"
|
||||||
|
#include "BMACommand.h"
|
||||||
|
|
||||||
|
BMAConsoleServer::BMAConsoleServer(BMAEPoll &ePoll, std::string url, short int port)
|
||||||
|
: BMATCPServerSocket(ePoll, url, port, "consoles") {
|
||||||
|
// ePoll.log.registerConsole(*this);
|
||||||
|
// ePoll.log.write(0) << "BMAConsole initializing..." << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
BMAConsoleServer::~BMAConsoleServer() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BMASession * BMAConsoleServer::getSocketAccept() {
|
||||||
|
return new BMAConsoleSession(ePoll, *this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMAConsoleServer::registerCommand(BMACommand &command) {
|
||||||
|
commands.push_back(&command);
|
||||||
|
}
|
||||||
|
|
||||||
|
int BMAConsoleServer::processCommand(BMASession *session) {
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
int sequence = 0;
|
||||||
|
|
||||||
|
for(BMASession *session : sessions) {
|
||||||
|
out << "|" << ++sequence;
|
||||||
|
out << "|" << session->getClientAddressAndPort();
|
||||||
|
out << "|" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
session->write((char *)out.str().c_str(), out.str().size());
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
\end{lstlisting}
|
||||||
|
|
||||||
|
\section{The Session}
|
||||||
|
|
||||||
|
\begin{lstlisting}[style=CStyle]
|
||||||
|
#include "includes"
|
||||||
|
#include "BMAEPoll.h"
|
||||||
|
#include "BMAMP3File.h"
|
||||||
|
#include "BMAConsoleServer.h"
|
||||||
|
#include "BMATCPServerSocket.h"
|
||||||
|
#include "BMAStreamServer.h"
|
||||||
|
#include "BMAHTTPServer.h"
|
||||||
|
#include "BMASIPServer.h"
|
||||||
|
#include "BMAHTTPRequestHandler.h"
|
||||||
|
#include "BMAMP3StreamContentProvider.h"
|
||||||
|
#include "BMATimer.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
std::string ipAddress = "0.0.0.0";
|
||||||
|
|
||||||
|
BMAEPoll ePoll;
|
||||||
|
ePoll.start(4, 1000);
|
||||||
|
|
||||||
|
//----------------------
|
||||||
|
// Testing TCP server.
|
||||||
|
//----------------------
|
||||||
|
|
||||||
|
BMATCPServerSocket tcpServer(ePoll, ipAddress, 1028, "users");
|
||||||
|
|
||||||
|
//------------------------
|
||||||
|
// MP3 Streaming Server
|
||||||
|
//------------------------
|
||||||
|
|
||||||
|
BMAStreamServer stream(ePoll, ipAddress, 1032, "listeners");
|
||||||
|
BMAMP3File tester(stream, "../extravaganza.mp3");
|
||||||
|
|
||||||
|
//--------------
|
||||||
|
// HTTP Server
|
||||||
|
//--------------
|
||||||
|
|
||||||
|
BMAHTTPServer http(ePoll, ipAddress, 1080, "http");
|
||||||
|
BMAHTTPRequestHandler handler1(http, "/");
|
||||||
|
|
||||||
|
//-------------
|
||||||
|
// SIP Server
|
||||||
|
//-------------
|
||||||
|
|
||||||
|
BMASIPServer sip(ePoll, ipAddress, 5061, "sip");
|
||||||
|
|
||||||
|
//-------------------------------------------------------------
|
||||||
|
// Console controller so the program can be monitored through
|
||||||
|
// a telnet session. BMATCPServerSocket can be registered as
|
||||||
|
// a command and will report its status when the command is
|
||||||
|
// entered on the console.
|
||||||
|
//-------------------------------------------------------------
|
||||||
|
|
||||||
|
BMAConsoleServer console(ePoll, ipAddress, 1027);
|
||||||
|
console.registerCommand(ePoll);
|
||||||
|
console.registerCommand(console);
|
||||||
|
console.registerCommand(http);
|
||||||
|
console.registerCommand(sip);
|
||||||
|
console.registerCommand(stream);
|
||||||
|
|
||||||
|
ePoll.start(4, 1000);
|
||||||
|
|
||||||
|
while(true)
|
||||||
|
sleep(300);
|
||||||
|
|
||||||
|
ePoll.stop();
|
||||||
|
|
||||||
|
}
|
||||||
|
\end{lstlisting}
|
||||||
|
|
||||||
|
\end{document}
|
||||||
|
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user