From 799df15ace5d750222682e6e88f76563f6f6d3a5 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Mon, 9 Mar 2020 18:29:28 +0100 Subject: [PATCH] Some updates --- server/src/server/udp-server/UDPServer.cpp | 10 +- server/src/server/udp-server/UDPServer.h | 212 +++++++++--------- .../VirtualServerBroadcastService.cpp | 10 +- .../services/VirtualServerBroadcastService.h | 60 ++--- 4 files changed, 146 insertions(+), 146 deletions(-) diff --git a/server/src/server/udp-server/UDPServer.cpp b/server/src/server/udp-server/UDPServer.cpp index 079c3d8..5fc4f5b 100644 --- a/server/src/server/udp-server/UDPServer.cpp +++ b/server/src/server/udp-server/UDPServer.cpp @@ -1,5 +1,5 @@ -// -// Created by WolverinDEV on 07/03/2020. -// - -#include "UDPServer.h" +// +// Created by WolverinDEV on 07/03/2020. +// + +#include "UDPServer.h" diff --git a/server/src/server/udp-server/UDPServer.h b/server/src/server/udp-server/UDPServer.h index d89632c..24d8070 100644 --- a/server/src/server/udp-server/UDPServer.h +++ b/server/src/server/udp-server/UDPServer.h @@ -1,107 +1,107 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace ts::server { - class VoiceClient; -} - -namespace ts::server::server::udp { - struct datagram_packet { - union pktinfo_storage { - in_pktinfo v4; - in6_pktinfo v6; - }; - - datagram_packet* next_packet; - - sockaddr_storage address; - pktinfo_storage address_info; - - size_t data_length; - uint8_t data[0]; - }; - static_assert(std::is_trivially_destructible::value); - static_assert(std::is_trivially_constructible::value); - - template - struct write_ring_queue { - std::array memory{}; - size_t current_index{0}; - size_t filled_index{0}; - - [[nodiscard]] constexpr inline auto max_size() const { return N; } - [[nodiscard]] inline size_t current_size() const { return this->filled_index - this->current_index; } - - [[nodiscard]] inline bool pop_entry(T& result) { - if(this->current_index >= this->filled_index) return false; - return this->memory[this->current_index++ % N]; - } - - [[nodiscard]] inline bool push_entry(T&& entry) { - if(this->filled_index - this->current_index >= N) return false; - this->memory[this->filled_index++ % N] = std::forward(entry); - return true; - } - }; - - struct io_loop; - struct io_loop_entry { - io_loop* io_loop{nullptr}; - - int file_descriptor{0}; - - event* event_read{}; - event* event_write{}; - - spin_lock write_queue_lock{}; - datagram_packet* dg_write_queue_head{nullptr}; - datagram_packet* dg_write_queue_tail{nullptr}; - - write_ring_queue, 1024 * 8> voice_write_queue{}; - }; - - struct io_loop { - std::thread base_dispatcher{}; - struct event_base* event_base{nullptr}; - - std::mutex entries_mutex{}; - std::vector registered_entries{}; - }; - - struct io_binding { - VirtualServerId server_id{0}; - sockaddr_storage address{}; - - size_t loop_entry_index{0}; - std::vector loop_entries{}; - - struct server_client { - std::shared_ptr client{}; - ClientId client_id{0}; - }; - - std::mutex client_lock{}; - std::deque known_clients{}; - }; - - class Server { - public: - - - void schedule_client_write(const std::shared_ptr& /* client */); - - void unregister_client(const std::shared_ptr& /* client */); - private: - std::mutex io_lock{}; - std::vector io_loops{}; - - std::mutex bindings_lock{}; - std::vector io_bindings{}; - }; +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace ts::server { + class VoiceClient; +} + +namespace ts::server::server::udp { + struct datagram_packet { + union pktinfo_storage { + in_pktinfo v4; + in6_pktinfo v6; + }; + + datagram_packet* next_packet; + + sockaddr_storage address; + pktinfo_storage address_info; + + size_t data_length; + uint8_t data[0]; + }; + static_assert(std::is_trivially_destructible::value); + static_assert(std::is_trivially_constructible::value); + + template + struct write_ring_queue { + std::array memory{}; + size_t current_index{0}; + size_t filled_index{0}; + + [[nodiscard]] constexpr inline auto max_size() const { return N; } + [[nodiscard]] inline size_t current_size() const { return this->filled_index - this->current_index; } + + [[nodiscard]] inline bool pop_entry(T& result) { + if(this->current_index >= this->filled_index) return false; + return this->memory[this->current_index++ % N]; + } + + [[nodiscard]] inline bool push_entry(T&& entry) { + if(this->filled_index - this->current_index >= N) return false; + this->memory[this->filled_index++ % N] = std::forward(entry); + return true; + } + }; + + struct io_loop; + struct io_loop_entry { + io_loop* io_loop{nullptr}; + + int file_descriptor{0}; + + event* event_read{}; + event* event_write{}; + + spin_lock write_queue_lock{}; + datagram_packet* dg_write_queue_head{nullptr}; + datagram_packet* dg_write_queue_tail{nullptr}; + + write_ring_queue, 1024 * 8> voice_write_queue{}; + }; + + struct io_loop { + std::thread base_dispatcher{}; + struct event_base* event_base{nullptr}; + + std::mutex entries_mutex{}; + std::vector registered_entries{}; + }; + + struct io_binding { + VirtualServerId server_id{0}; + sockaddr_storage address{}; + + size_t loop_entry_index{0}; + std::vector loop_entries{}; + + struct server_client { + std::shared_ptr client{}; + ClientId client_id{0}; + }; + + std::mutex client_lock{}; + std::deque known_clients{}; + }; + + class Server { + public: + + + void schedule_client_write(const std::shared_ptr& /* client */); + + void unregister_client(const std::shared_ptr& /* client */); + private: + std::mutex io_lock{}; + std::vector io_loops{}; + + std::mutex bindings_lock{}; + std::vector io_bindings{}; + }; } \ No newline at end of file diff --git a/server/src/services/VirtualServerBroadcastService.cpp b/server/src/services/VirtualServerBroadcastService.cpp index 2cc9d4c..1c2941b 100644 --- a/server/src/services/VirtualServerBroadcastService.cpp +++ b/server/src/services/VirtualServerBroadcastService.cpp @@ -1,5 +1,5 @@ -// -// Created by WolverinDEV on 07/03/2020. -// - -#include "VirtualServerBroadcastService.h" +// +// Created by WolverinDEV on 07/03/2020. +// + +#include "VirtualServerBroadcastService.h" diff --git a/server/src/services/VirtualServerBroadcastService.h b/server/src/services/VirtualServerBroadcastService.h index 7742b10..eb5a25e 100644 --- a/server/src/services/VirtualServerBroadcastService.h +++ b/server/src/services/VirtualServerBroadcastService.h @@ -1,31 +1,31 @@ -#pragma once - -#include -#include -#include - -namespace ts::server { - class ConnectedClient; -} - -namespace ts::server::vserver { - class VirtualServerBase; - - class BroadcastService { - public: - explicit BroadcastService(VirtualServerBase*); - - bool client_updated(const std::shared_ptr& /* client */, - const std::deque>& /* keys */, bool /* notify_client */ = true); - - inline bool client_updated(const std::shared_ptr& client, const std::deque& keys, bool notify_client = true) { - if(keys.empty()) return false; - - std::deque> _keys{}; - for(const auto& key : keys) _keys.push_back(property::impl::info(key)); - return this->client_updated(client, _keys, notify_client); - }; - private: - VirtualServerBase* virtual_server_; - }; +#pragma once + +#include +#include +#include + +namespace ts::server { + class ConnectedClient; +} + +namespace ts::server::vserver { + class VirtualServerBase; + + class BroadcastService { + public: + explicit BroadcastService(VirtualServerBase*); + + bool client_updated(const std::shared_ptr& /* client */, + const std::deque>& /* keys */, bool /* notify_client */ = true); + + inline bool client_updated(const std::shared_ptr& client, const std::deque& keys, bool notify_client = true) { + if(keys.empty()) return false; + + std::deque> _keys{}; + for(const auto& key : keys) _keys.push_back(property::impl::info(key)); + return this->client_updated(client, _keys, notify_client); + }; + private: + VirtualServerBase* virtual_server_; + }; } \ No newline at end of file