8#include "RequestHandler.h"
9#include "RAFTConsensus.h"
10#include "Statistics.h"
12#include <boost/shared_ptr.hpp>
13#include <boost/enable_shared_from_this.hpp>
14#include <boost/asio.hpp>
17#define CONNECTION_TIMEOUT 10000000
19using boost::asio::ip::tcp;
55 :
public boost::enable_shared_from_this<TcpConnection>
58 typedef boost::shared_ptr<TcpConnection> pointer;
63 static pointer
create(boost::asio::io_context& ioContext);
73 virtual void sendData(
const std::string &data, boost::system::error_code &error);
94 void readExpectedData(
int &size, std::vector<char> &data, std::string &totalData,
95 boost::system::error_code &error);
124 void handleAccept(TcpConnection::pointer newConnection,
const boost::system::error_code& error);
126 boost::asio::io_context& ioContext_;
127 tcp::acceptor acceptor_;
131 bool stopped =
false;
Handles connections with database.
Definition: ConnectionHandler.h:27
void startListen(DatabaseHandler *databaseHandler, DatabaseConnection *databaseConnection, RAFTConsensus *raft, Statistics *stats, int port=PORT, RequestHandler *handler=nullptr)
Starts listening for requests. Takes in a pointer to the database handler.
Definition: ConnectionHandler.cpp:23
Handles interaction with database when dealing with job requests.
Definition: DatabaseConnection.h:25
Handles interaction with database.
Definition: DatabaseHandler.h:23
Definition: RAFTConsensus.h:41
Definition: RequestHandler.h:43
Stores the Prometheus statistics variables.
Definition: Statistics.h:35
Definition: ConnectionHandler.h:56
static pointer create(boost::asio::io_context &ioContext)
Creates the pointer to the tcp connection. Takes in the io context.
Definition: ConnectionHandler.cpp:51
TcpConnection(boost::asio::io_context &ioContext)
Constructor. Not public because you need to use the create method. Not private because we need this c...
Definition: ConnectionHandler.h:85
virtual void start(RequestHandler *handler, pointer thisPointer, Statistics *stats)
Starts the handeling of a request. Takes in the request handler to call.
Definition: ConnectionHandler.cpp:61
virtual void sendData(const std::string &data, boost::system::error_code &error)
Sends the given data to the other side of the connection.
Definition: ConnectionHandler.cpp:56
Definition: ConnectionHandler.h:103
void stop()
Stops the server.
Definition: ConnectionHandler.cpp:167