Added some notes.

This commit is contained in:
Relintai 2022-02-10 14:35:26 +01:00
parent 059cae3625
commit 4f39060341
7 changed files with 28 additions and 2 deletions

View File

@ -36,6 +36,10 @@
#include "event_loop.h"
#include <functional>
// Inherit from socket?
// Could be called ServerSocket
// New connection callback -> make it a virtual func?
using NewConnectionCallback = std::function<void(int fd, const InetAddress &)>;
class Acceptor {
protected:

View File

@ -35,6 +35,7 @@
#include <functional>
#include <memory>
class EventLoop;
/**
* @brief This class is used to implement reactor pattern. A Channel object

View File

@ -35,6 +35,10 @@
#include <atomic>
#include <memory>
// inherit from socket?
// Could be called ClientSocket
// New connection callback -> make it a virtual func?
class Connector : public std::enable_shared_from_this<Connector> {
protected:
Connector(const Connector &) = delete;

View File

@ -99,8 +99,7 @@ TcpClient::~TcpClient() {
loop_->runInLoop([conn, loop]() {
conn->setCloseCallback([loop](const TcpConnectionPtr &connPtr) {
loop->queueInLoop([connPtr]() {
static_cast<TcpConnectionImpl *>(connPtr.get())
->connectDestroyed();
static_cast<TcpConnectionImpl *>(connPtr.get())->connectDestroyed();
});
});
});

View File

@ -43,6 +43,16 @@ class Connector;
using ConnectorPtr = std::shared_ptr<Connector>;
class SSLContext;
//maybe:
//Reference -> Socket -> ConnectionListener (Channel?) -> Connector (ClientSocket) -> TcpClient
// -> Acceptor (ServerSocket) -> TcpServer
//Reference -> TcpConnection (with a connectionlistener member) -> TcpConnectionDefault
//Also todo move around the core net classes a bit more
//should be ConnectionListener derived
//Inherit from Connector (which Could be called ClientSocket)?
class TcpClient {
protected:
TcpClient(const TcpClient &) = delete;

View File

@ -38,6 +38,10 @@
#include <memory>
#include <string>
// add new class TcpConnectionListener or ConnectionListener
//set_listener(ConnectionListener)
// instead of callbacks
class SSLContext;
std::shared_ptr<SSLContext> newSSLServerContext(const std::string &certPath, const std::string &keyPath, bool useOldTLS = false, const std::vector<std::pair<std::string, std::string> > &sslConfCmds = {});

View File

@ -44,6 +44,8 @@
class Acceptor;
class SSLContext;
//Inherit from Acceptor (-> Could be called ServerSocket)?
class TcpServer {
protected:
TcpServer(const TcpServer &) = delete;
@ -125,7 +127,9 @@ public:
private:
EventLoop *loop_;
std::unique_ptr<Acceptor> acceptorPtr_;
void newConnection(int fd, const InetAddress &peer);
std::string serverName_;
std::set<TcpConnectionPtr> connSet_;