From 4f3906034166473e8a36c790a757f3c702a221e3 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 10 Feb 2022 14:35:26 +0100 Subject: [PATCH] Added some notes. --- core/loops/acceptor.h | 4 ++++ core/loops/channel.h | 1 + core/net/connector.h | 4 ++++ core/net/tcp_client.cpp | 3 +-- core/net/tcp_client.h | 10 ++++++++++ core/net/tcp_connection.h | 4 ++++ core/net/tcp_server.h | 4 ++++ 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/core/loops/acceptor.h b/core/loops/acceptor.h index c194b21..d336c37 100644 --- a/core/loops/acceptor.h +++ b/core/loops/acceptor.h @@ -36,6 +36,10 @@ #include "event_loop.h" #include +// Inherit from socket? +// Could be called ServerSocket +// New connection callback -> make it a virtual func? + using NewConnectionCallback = std::function; class Acceptor { protected: diff --git a/core/loops/channel.h b/core/loops/channel.h index e073466..96b0040 100644 --- a/core/loops/channel.h +++ b/core/loops/channel.h @@ -35,6 +35,7 @@ #include #include + class EventLoop; /** * @brief This class is used to implement reactor pattern. A Channel object diff --git a/core/net/connector.h b/core/net/connector.h index c10e41a..4fc3cb1 100644 --- a/core/net/connector.h +++ b/core/net/connector.h @@ -35,6 +35,10 @@ #include #include +// inherit from socket? +// Could be called ClientSocket +// New connection callback -> make it a virtual func? + class Connector : public std::enable_shared_from_this { protected: Connector(const Connector &) = delete; diff --git a/core/net/tcp_client.cpp b/core/net/tcp_client.cpp index 2d587b7..2cf0a2e 100644 --- a/core/net/tcp_client.cpp +++ b/core/net/tcp_client.cpp @@ -99,8 +99,7 @@ TcpClient::~TcpClient() { loop_->runInLoop([conn, loop]() { conn->setCloseCallback([loop](const TcpConnectionPtr &connPtr) { loop->queueInLoop([connPtr]() { - static_cast(connPtr.get()) - ->connectDestroyed(); + static_cast(connPtr.get())->connectDestroyed(); }); }); }); diff --git a/core/net/tcp_client.h b/core/net/tcp_client.h index 61b442b..b633a79 100644 --- a/core/net/tcp_client.h +++ b/core/net/tcp_client.h @@ -43,6 +43,16 @@ class Connector; using ConnectorPtr = std::shared_ptr; 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; diff --git a/core/net/tcp_connection.h b/core/net/tcp_connection.h index c5e5690..2c25f95 100644 --- a/core/net/tcp_connection.h +++ b/core/net/tcp_connection.h @@ -38,6 +38,10 @@ #include #include +// add new class TcpConnectionListener or ConnectionListener +//set_listener(ConnectionListener) +// instead of callbacks + class SSLContext; std::shared_ptr newSSLServerContext(const std::string &certPath, const std::string &keyPath, bool useOldTLS = false, const std::vector > &sslConfCmds = {}); diff --git a/core/net/tcp_server.h b/core/net/tcp_server.h index 6fbb7b4..143722d 100644 --- a/core/net/tcp_server.h +++ b/core/net/tcp_server.h @@ -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 acceptorPtr_; + void newConnection(int fd, const InetAddress &peer); + std::string serverName_; std::set connSet_;