qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
server.h
Go to the documentation of this file.
1
24
25#ifndef QB_IO_ASYNC_UDP_SERVER_H
26#define QB_IO_ASYNC_UDP_SERVER_H
27
28#include "../../transport/udp.h"
29#include "../io.h"
30
31namespace qb::io::async::udp {
32
44template <typename _Derived>
45class server
46 : public io<_Derived>
47 , public transport::udp {
48public:
49 constexpr static const bool has_server =
50 false;
51
59 server() noexcept {
60 if constexpr (has_member_Protocol<_Derived>::value) {
61 if constexpr (!std::is_void_v<typename _Derived::Protocol>) {
63 static_cast<_Derived &>(*this));
64 }
65 }
66 }
67};
68
69// Note: The following code is commented out in the original file but preserved
70// for reference. It represents an alternative implementation of a UDP server
71// that tracks client sessions.
72
74// * @class server
75// * @brief Alternative UDP server implementation with session tracking
76// *
77// * This template class implements a more complex UDP server that tracks
78// * client sessions based on their endpoint identity.
79// *
80// * @tparam _Derived The derived class type (CRTP pattern)
81// * @tparam _Session The session class type for handling client communications
82// */
83// template <typename _Derived, typename _Session>
84// class server : public io<server<_Derived, _Session>> {
85// public:
86// using base_t = io<server<_Derived, _Session>>;
87// using session_map_t = qb::unordered_map<transport::udp::identity, _Session,
88// transport::udp::identity::hasher>;
89//
90// private:
91// session_map_t _sessions{};
92//
93// public:
94// using IOSession = _Session;
95// server() = default;
96//
97// session_map_t &
98// sessions() {
99// return _sessions;
100// }
101//
102// void
103// on(transport::udp::message message, std::size_t size) {
104// auto it = _sessions.find(message.ident);
105// if (it == _sessions.end()) {
106// it = _sessions.emplace(message.ident, static_cast<_Derived
107// &>(*this)).first; it->second.ident() = message.ident;
108// }
109// // return; // drop the message
110//
111// memcpy(it->second.buffer().allocate_back(size), message.data, size);
112// auto ret = 0;
113// while ((ret = it->second.getMessageSize()) > 0) {
114// it->second.on(it->second.getMessage(ret), ret);
115// it->second.flush(ret);
116// }
117// }
118//
119// void
120// stream(char const *message, std::size_t size) {
121// for (auto &session : sessions())
122// session.second.publish(message, size);
123// }
124//
125// bool
126// disconnected() const {
127// throw std::runtime_error("Server had been disconnected");
128// return true;
129// }
130//
131// void
132// disconnected(transport::udp::identity ident) {
133// _sessions.erase(ident);
134// }
135//};
136
137} // namespace qb::io::async::udp
138
139#endif // QB_IO_ASYNC_UDP_SERVER_H
_Protocol * switch_protocol(_Args &&...args)
Switches to a new protocol for I/O processing, taking ownership.
Definition io.h:988
io()=default
Default constructor.
server() noexcept
Constructor.
Definition server.h:59
static constexpr const bool has_server
Flag indicating server association (false for UDP servers)
Definition server.h:49
UDP transport providing connectionless, datagram-based communication.
Definition udp.h:44
Core asynchronous I/O class templates for event-driven operations.
UDP datagram transport implementation for the QB IO library.