Some updates

This commit is contained in:
WolverinDEV 2020-03-09 18:29:28 +01:00
parent 7926a26091
commit 799df15ace
4 changed files with 146 additions and 146 deletions

View File

@ -1,5 +1,5 @@
//
// Created by WolverinDEV on 07/03/2020.
//
#include "UDPServer.h"
//
// Created by WolverinDEV on 07/03/2020.
//
#include "UDPServer.h"

View File

@ -1,107 +1,107 @@
#pragma once
#include <thread>
#include <event.h>
#include <vector>
#include <misc/spin_lock.h>
#include <Definitions.h>
#include <mutex>
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<datagram_packet>::value);
static_assert(std::is_trivially_constructible<datagram_packet>::value);
template <typename T, size_t N>
struct write_ring_queue {
std::array<T, N> 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<std::weak_ptr<VoiceClient>, 1024 * 8> voice_write_queue{};
};
struct io_loop {
std::thread base_dispatcher{};
struct event_base* event_base{nullptr};
std::mutex entries_mutex{};
std::vector<io_loop_entry*> registered_entries{};
};
struct io_binding {
VirtualServerId server_id{0};
sockaddr_storage address{};
size_t loop_entry_index{0};
std::vector<io_loop_entry*> loop_entries{};
struct server_client {
std::shared_ptr<VoiceClient> client{};
ClientId client_id{0};
};
std::mutex client_lock{};
std::deque<server_client> known_clients{};
};
class Server {
public:
void schedule_client_write(const std::shared_ptr<VoiceClient>& /* client */);
void unregister_client(const std::shared_ptr<VoiceClient>& /* client */);
private:
std::mutex io_lock{};
std::vector<io_loop*> io_loops{};
std::mutex bindings_lock{};
std::vector<io_binding*> io_bindings{};
};
#pragma once
#include <thread>
#include <event.h>
#include <vector>
#include <misc/spin_lock.h>
#include <Definitions.h>
#include <mutex>
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<datagram_packet>::value);
static_assert(std::is_trivially_constructible<datagram_packet>::value);
template <typename T, size_t N>
struct write_ring_queue {
std::array<T, N> 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<std::weak_ptr<VoiceClient>, 1024 * 8> voice_write_queue{};
};
struct io_loop {
std::thread base_dispatcher{};
struct event_base* event_base{nullptr};
std::mutex entries_mutex{};
std::vector<io_loop_entry*> registered_entries{};
};
struct io_binding {
VirtualServerId server_id{0};
sockaddr_storage address{};
size_t loop_entry_index{0};
std::vector<io_loop_entry*> loop_entries{};
struct server_client {
std::shared_ptr<VoiceClient> client{};
ClientId client_id{0};
};
std::mutex client_lock{};
std::deque<server_client> known_clients{};
};
class Server {
public:
void schedule_client_write(const std::shared_ptr<VoiceClient>& /* client */);
void unregister_client(const std::shared_ptr<VoiceClient>& /* client */);
private:
std::mutex io_lock{};
std::vector<io_loop*> io_loops{};
std::mutex bindings_lock{};
std::vector<io_binding*> io_bindings{};
};
}

View File

@ -1,5 +1,5 @@
//
// Created by WolverinDEV on 07/03/2020.
//
#include "VirtualServerBroadcastService.h"
//
// Created by WolverinDEV on 07/03/2020.
//
#include "VirtualServerBroadcastService.h"

View File

@ -1,31 +1,31 @@
#pragma once
#include <memory>
#include <deque>
#include <Properties.h>
namespace ts::server {
class ConnectedClient;
}
namespace ts::server::vserver {
class VirtualServerBase;
class BroadcastService {
public:
explicit BroadcastService(VirtualServerBase*);
bool client_updated(const std::shared_ptr<ConnectedClient>& /* client */,
const std::deque<std::shared_ptr<property::PropertyDescription>>& /* keys */, bool /* notify_client */ = true);
inline bool client_updated(const std::shared_ptr<ConnectedClient>& client, const std::deque<property::ClientProperties>& keys, bool notify_client = true) {
if(keys.empty()) return false;
std::deque<std::shared_ptr<property::PropertyDescription>> _keys{};
for(const auto& key : keys) _keys.push_back(property::impl::info<property::ClientProperties>(key));
return this->client_updated(client, _keys, notify_client);
};
private:
VirtualServerBase* virtual_server_;
};
#pragma once
#include <memory>
#include <deque>
#include <Properties.h>
namespace ts::server {
class ConnectedClient;
}
namespace ts::server::vserver {
class VirtualServerBase;
class BroadcastService {
public:
explicit BroadcastService(VirtualServerBase*);
bool client_updated(const std::shared_ptr<ConnectedClient>& /* client */,
const std::deque<std::shared_ptr<property::PropertyDescription>>& /* keys */, bool /* notify_client */ = true);
inline bool client_updated(const std::shared_ptr<ConnectedClient>& client, const std::deque<property::ClientProperties>& keys, bool notify_client = true) {
if(keys.empty()) return false;
std::deque<std::shared_ptr<property::PropertyDescription>> _keys{};
for(const auto& key : keys) _keys.push_back(property::impl::info<property::ClientProperties>(key));
return this->client_updated(client, _keys, notify_client);
};
private:
VirtualServerBase* virtual_server_;
};
}