From 44f772a7442e617d4a93c0b3ed318ffb42991d8b Mon Sep 17 00:00:00 2001 From: Christian Krinitsin Date: Fri, 21 Mar 2025 10:42:09 +0100 Subject: implement communication between server and client (without mutexes and with queue_length of 1) --- src/common/shared_memory.h | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'src/common/shared_memory.h') diff --git a/src/common/shared_memory.h b/src/common/shared_memory.h index 53c7fb7..43fe2f5 100644 --- a/src/common/shared_memory.h +++ b/src/common/shared_memory.h @@ -1,16 +1,39 @@ #pragma once #include +#include -#define QUEUE_SIZE 10 #define SHM_NAME "/hashtable_queue" +#define MAX_KEY_SIZE 64 +#define MAX_VALUE_SIZE 128 -enum Operations { INSERT, DELETE, GET }; +enum Operations { INSERT, DELETE, GET, PRINT }; + +struct Request { + Operations type; + char key[MAX_KEY_SIZE]; + char value[MAX_VALUE_SIZE]; +}; struct SharedMemory { - pthread_mutex_t mutex; - pthread_cond_t cond_var; - Operations queue[QUEUE_SIZE]; - int head; - int tail; + Request request; + bool processed; + char response[MAX_VALUE_SIZE]; }; + +template +std::string serialize(const T& data) +{ + std::ostringstream oss; + oss << data; + return oss.str(); +} + +template +T deserialize(const std::string& str) +{ + std::istringstream iss(str); + T data; + iss >> data; + return data; +} -- cgit 1.4.1