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
info.hxx
1#pragma once
2
3#include <StormByte/expected.hxx>
4#include <StormByte/network/exception.hxx>
5#include <StormByte/network/connection/handler.hxx>
6#include <StormByte/network/connection/protocol.hxx>
7
8#ifdef WINDOWS
9#include <winsock2.h>
10#else
11#include <sys/socket.h>
12#endif
13
14#include <memory>
15#include <string>
16
21namespace StormByte::Network::Connection {
22 constexpr const unsigned short DEFAULT_MTU = 1500;
23
28 class STORMBYTE_NETWORK_PUBLIC Info {
29 public:
34 Info(const Info& other) noexcept = delete;
35
40 Info(Info&& other) noexcept = default;
41
45 ~Info() noexcept = default;
46
52 Info& operator=(const Info& other) noexcept = delete;
53
59 Info& operator=(Info&& other) noexcept = default;
60
69 static StormByte::Expected<Info, Exception> FromHost(const std::string& hostname, const unsigned short& port, const Protocol& protocol, std::shared_ptr<const Handler> handler) noexcept;
70
76 static StormByte::Expected<Info, Exception> FromSockAddr(std::shared_ptr<sockaddr> sockaddr) noexcept;
77
82 constexpr const std::string& IP() const noexcept {
83 return m_ip;
84 }
85
90 constexpr const unsigned short& Port() const noexcept {
91 return m_port;
92 }
93
98 inline std::shared_ptr<const sockaddr> SockAddr() const noexcept {
99 return m_sock_addr;
100 }
101
102 private:
103 std::shared_ptr<sockaddr> m_sock_addr;
104 unsigned int m_mtu;
105 std::string m_ip;
106 unsigned short m_port;
107
112 Info(std::shared_ptr<sockaddr> sock_addr) noexcept;
113
122 static StormByte::Expected<std::shared_ptr<sockaddr>, Exception> ResolveHostname(const std::string& hostname, const unsigned short& port, const Protocol& protocol, std::shared_ptr<const Handler> handler) noexcept;
123
129 void Initialize(std::shared_ptr<sockaddr> sock_addr) noexcept;
130 };
131}
The class representing the connection information.
Definition info.hxx:28
Info(const Info &other) noexcept=delete
The copy constructor of the Info class.
constexpr const unsigned short & Port() const noexcept
The function to get the port.
Definition info.hxx:90
std::shared_ptr< const sockaddr > SockAddr() const noexcept
The function to get the socket address.
Definition info.hxx:98
~Info() noexcept=default
The destructor of the Info class.
Info(Info &&other) noexcept=default
The move constructor of the Info class.
The class representing an exception in the network module.
Definition exception.hxx:15