summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2022-12-18 16:53:46 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2022-12-18 16:53:46 +0100
commit9eefbb4afc9601024eac6191addd98e21f90a5b3 (patch)
treee26771a2ba2d93c58940f011d8701372419f6cb8 /include
parent40027e44e5d0f0040238cfc1bd6a8d80c17c54fb (diff)
multithread outgoing network messages, thread safe allocator, refactor
Diffstat (limited to 'include')
-rw-r--r--include/allocator.h2
-rw-r--r--include/list.h1
-rw-r--r--include/protocol.h24
3 files changed, 25 insertions, 2 deletions
diff --git a/include/allocator.h b/include/allocator.h
index d1fe9f4..a1c8bf0 100644
--- a/include/allocator.h
+++ b/include/allocator.h
@@ -7,10 +7,12 @@ typedef struct t_allocator {
void* memory;
uint64_t cursor;
uint64_t size;
+ mutex mutex;
} allocator;
allocator create_allocator(uint64_t size);
void* allocator_alloc(allocator* al, uint64_t size);
void destroy_allocator(allocator* al);
+void allocator_clear(allocator* al);
#endif \ No newline at end of file
diff --git a/include/list.h b/include/list.h
index 41a5705..db174c7 100644
--- a/include/list.h
+++ b/include/list.h
@@ -17,6 +17,7 @@ typedef struct t_list
list_item *start;
u32 count;
u16 size;
+ mutex mutex;
allocator* al;
} list;
diff --git a/include/protocol.h b/include/protocol.h
index 0ec87d7..39e7d6a 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -3,6 +3,8 @@
#include <projectbase/project_base.h>
+#include "list.h"
+
typedef enum t_network_message_type
{
MESSAGE_GET_ID_UPSTREAM,
@@ -100,8 +102,19 @@ typedef struct t_protocol_user_shoot
float diry;
} protocol_user_shoot;
-#define MAX_NETWORK_BUFFER_SIZE 50000
-u8 network_buffer[50000];
+typedef struct t_send_queue_entry {
+ bool active;
+ network_client recipients[10];
+ network_message message;
+} send_queue_entry;
+
+#define MAX_NETWORK_BUFFER_SIZE 5000000
+u8 network_buffer[MAX_NETWORK_BUFFER_SIZE];
+
+allocator server_incomming_allocator;
+allocator client_incomming_allocator;
+allocator outgoing_allocator;
+
network_message create_protocol_get_id_up(u32 id);
network_message create_protocol_get_id_down(u32 id);
network_message create_protocol_user_list();
@@ -115,6 +128,13 @@ network_message create_protocol_drop_list();
array messages_received_on_server;
array messages_received_on_client;
+#define OUTGOING_QUEUE_SIZE 100
+mutex messages_to_send_queue_mutex;
+send_queue_entry messages_to_send_queue[OUTGOING_QUEUE_SIZE] = {0};
+
+void add_message_to_outgoing_queue(send_queue_entry entry);
+void* network_send_thread(void* args);
+
void server_on_message_received(u8 *buffer, u32 length, u64 timestamp, network_client client);
void client_on_message_received(u8 *buffer, u32 length);