MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
port_mapping.hpp
Go to the documentation of this file.
1#ifndef ASTEROIDS_NET_PORT_MAPPING_HPP
2#define ASTEROIDS_NET_PORT_MAPPING_HPP
3
4/**
5 * @file port_mapping.hpp
6 * @brief Automatic UDP port mapping for hosted multiplayer sessions.
7 */
8
9#include <cstdint>
10#include <string>
11
12namespace space {
13
14 /**
15 * @class PortMapping
16 * @brief Owns an automatically created UPnP or NAT-PMP port mapping.
17 *
18 * Destroying the object removes any mapping successfully created by open().
19 */
21 public:
22 /** @brief Creates an inactive port mapping. */
23 PortMapping() = default;
24 /** @brief Removes the active mapping, if one was created. */
26 PortMapping(const PortMapping &) = delete;
27 PortMapping &operator=(const PortMapping &) = delete;
28
29 /**
30 * @brief Attempts to expose a local UDP port through the router.
31 * @param port Decimal UDP port number to map.
32 */
33 void open(const std::string &port);
34 /** @brief Returns a human-readable description of the mapping result. */
35 [[nodiscard]] const std::string &status() const;
36
37 private:
38 enum class Method {
39 None,
40 Upnp,
41 NatPmp
42 };
43
44 Method method = Method::None;
45 std::uint16_t private_port = 0;
46 std::uint16_t public_port = 0;
47 std::string status_message = "Automatic router mapping unavailable; forward the UDP port manually.";
48 };
49
50} // namespace space
51
52#endif
PortMapping(const PortMapping &)=delete
~PortMapping()
Removes the active mapping, if one was created.
void open(const std::string &port)
Attempts to expose a local UDP port through the router.
PortMapping & operator=(const PortMapping &)=delete
const std::string & status() const
Returns a human-readable description of the mapping result.
PortMapping()=default
Creates an inactive port mapping.