diff options
| author | Christian Krinitsin <mail@krinitsin.com> | 2025-03-21 10:42:09 +0100 |
|---|---|---|
| committer | Christian Krinitsin <mail@krinitsin.com> | 2025-03-21 10:42:09 +0100 |
| commit | 44f772a7442e617d4a93c0b3ed318ffb42991d8b (patch) | |
| tree | b8cb1009b3a089a75fe15c600386cd96cac5c9d9 /src/common | |
| parent | 20ae154d21b8b9111e550b936ea23325a6de8e84 (diff) | |
| download | BT-Programming-Assignment-44f772a7442e617d4a93c0b3ed318ffb42991d8b.tar.gz BT-Programming-Assignment-44f772a7442e617d4a93c0b3ed318ffb42991d8b.zip | |
implement communication between server and client (without mutexes and with queue_length of 1)
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/shared_memory.h | 37 |
1 files changed, 30 insertions, 7 deletions
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 <pthread.h> +#include <sstream> -#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 <typename T> +std::string serialize(const T& data) +{ + std::ostringstream oss; + oss << data; + return oss.str(); +} + +template <typename T> +T deserialize(const std::string& str) +{ + std::istringstream iss(str); + T data; + iss >> data; + return data; +} |