StormByte C++ Library: Network module 0.0.9999
StormByte-Network is a StormByte library module for handling and create network connections
Loading...
Searching...
No Matches
endpoint.hxx
1#pragma once
2
3#include <StormByte/buffer/pipeline.hxx>
4#include <StormByte/network/connection/handler.hxx>
5#include <StormByte/network/packet.hxx>
6#include <StormByte/network/typedefs.hxx>
7#include <StormByte/logger.hxx>
8
9#include <atomic>
10
15namespace StormByte::Network {
20 class STORMBYTE_NETWORK_PUBLIC EndPoint {
21 public:
28 EndPoint(const Connection::Protocol& protocol, std::shared_ptr<Connection::Handler> handler, std::shared_ptr<Logger> logger) noexcept;
29
33 EndPoint(const EndPoint& other) = delete;
34
38 EndPoint(EndPoint&& other) noexcept = default;
39
43 virtual ~EndPoint() noexcept;
44
48 EndPoint& operator=(const EndPoint& other) = delete;
49
53 EndPoint& operator=(EndPoint&& other) noexcept = default;
54
61 virtual ExpectedVoid Connect(const std::string& host, const unsigned short& port) noexcept = 0;
62
66 virtual void Disconnect() noexcept;
67
72 const Connection::Protocol& Protocol() const noexcept;
73
78 Connection::Status Status() const noexcept;
79
80 protected:
81 Connection::Protocol m_protocol;
82 std::shared_ptr<Connection::Handler> m_handler;
83 std::shared_ptr<Logger> m_logger;
84 std::atomic<Connection::Status> m_status;
85 Socket::Socket* m_socket;
86 Buffer::Pipeline m_input_pipeline, m_output_pipeline;
87
93 virtual ExpectedVoid Handshake(Socket::Client& client) noexcept;
94
100 virtual ExpectedVoid Authenticate(Socket::Client& client) noexcept;
101
108 ExpectedPacket Receive(Socket::Client& client) noexcept;
109
115 ExpectedPacket RawReceive(Socket::Client& client) noexcept;
116
123 ExpectedVoid Send(Socket::Client& client, const Packet& packet) noexcept;
124
131 ExpectedVoid RawSend(Socket::Client& client, const Packet& packet) noexcept;
132
133 private:
140 ExpectedPacket Receive(Socket::Client& client, Buffer::Pipeline& pipeline) noexcept;
141
149 ExpectedVoid Send(Socket::Client& client, const Packet& packet, Buffer::Pipeline& pipeline) noexcept;
150 };
151}
The class representing a client.
Definition client.hxx:15
Represents a network endpoint, serving as a base class for both clients and servers.
Definition endpoint.hxx:20
virtual ~EndPoint() noexcept
Virtual destructor for proper cleanup in derived classes.
EndPoint(const Connection::Protocol &protocol, std::shared_ptr< Connection::Handler > handler, std::shared_ptr< Logger > logger) noexcept
Constructs an EndPoint with the specified protocol, handler, and logger.
EndPoint(const EndPoint &other)=delete
Deleted copy constructor to prevent copying.
EndPoint(EndPoint &&other) noexcept=default
Defaulted move constructor.
Represents a network packet.
Definition packet.hxx:21
The namespace containing connection items.
Contains all the network-related classes and utilities.
Definition client.hxx:10
StormByte::Expected< std::shared_ptr< Packet >, PacketError > ExpectedPacket
The expected packet type.
Definition typedefs.hxx:38
StormByte::Expected< void, ConnectionError > ExpectedVoid
The expected void type.
Definition typedefs.hxx:32