43#include <StormByte/buffer/consumer.hxx>
44#include <StormByte/buffer/fifo.hxx>
45#include <StormByte/expected.hxx>
46#include <StormByte/logger/log.hxx>
52#include <StormByte/safe/pointers.hxx>
53#include <StormByte/type_traits.hxx>
93 namespace Connection {
177 template<typename Callable>
181 m_context(new
std::decay_t<Callable>(
std::forward<Callable>(callable))),
182 m_invoke(&Invoke<
std::decay_t<Callable>>),
183 m_clone(&Clone<
std::decay_t<Callable>>),
184 m_destroy(&Destroy<
std::decay_t<Callable>>) {}
231 explicit operator
bool() const noexcept {
232 return m_context !=
nullptr;
245 template<
typename Callable>
248 return (*
static_cast<Callable*
>(context))(opcode, std::move(payload), std::move(logger));
257 template<
typename Callable>
258 static void* Clone(
const void* context) {
259 return new Callable(*
static_cast<const Callable*
>(context));
267 template<
typename Callable>
268 static void Destroy(
void* context)
noexcept {
269 delete static_cast<Callable*
>(context);
272 void* m_context =
nullptr;
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
Forward declaration of the connected client implementation.
Forward declaration of the socket abstraction.
Connection or socket operation failed.
Definition exception.hxx:163
Caller-owned callback that builds a packet from opcode and payload.
Definition typedefs.hxx:143
~DeserializePacketFunction() noexcept
Destroy through the caller's destruction trampoline.
Transport::Packet::OpcodeType OpcodeType
Wire opcode type.
Definition typedefs.hxx:148
DeserializePacketFunction(DeserializePacketFunction &&other) noexcept
Transfer callback ownership without touching its target.
void(*)(void *) noexcept DestroyFunction
Caller-allocator destroy trampoline taking context storage.
Definition typedefs.hxx:165
void *(*)(const void *) CloneFunction
Caller-allocator clone trampoline taking source context storage.
Definition typedefs.hxx:160
PacketPointer(*)(void *, OpcodeType, Buffer::Consumer, StormByte::Safe::Shared< Logger::Log >) InvokeFunction
Invocation trampoline taking context, opcode, payload, and logger.
Definition typedefs.hxx:154
DeserializePacketFunction() noexcept=default
Construct an empty callback.
DeserializePacketFunction(const DeserializePacketFunction &other)
Clone using the caller's target allocator trampoline.
unsigned short OpcodeType
Opcode storage type.
Definition packet.hxx:78
int HandlerType
Native POSIX socket handle.
Definition typedefs.hxx:98
Private native transport implementation.
Network module of the StormByte suite.
StormByte::Expected< Buffer::FIFO, ConnectionError > ExpectedBuffer
Receive buffer or connection error result.
Definition typedefs.hxx:110
StormByte::Expected< void, ConnectionError > ExpectedVoid
Void operation or connection error result.
Definition typedefs.hxx:115
StormByte::Expected< Connection::Read::Result, ConnectionClosed > ExpectedReadResult
Wait-for-data result or closed connection error.
Definition typedefs.hxx:125
StormByte::Safe::Shared< Transport::Packet > PacketPointer
Base-heap shared packet pointer.
Definition typedefs.hxx:132
StormByte::Expected< StormByte::Safe::Shared< Socket::Client >, ConnectionError > ExpectedClient
Accepted client or connection error result.
Definition typedefs.hxx:120
Root namespace of the StormByte suite.
std::conditional_t< Type::Reference< T >, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, Safe::Shared< E > >, std::expected< T, Safe::Shared< E > > > Expected
#define STORMBYTE_NETWORK_PUBLIC
Definition visibility.h:51