diff options
| author | Christian Krinitsin <mail@krinitsin.com> | 2025-03-21 16:33:37 +0100 |
|---|---|---|
| committer | Christian Krinitsin <mail@krinitsin.com> | 2025-03-21 16:33:37 +0100 |
| commit | 435ffba7c3005e643a8d6f7fed54d0f556ee2ad7 (patch) | |
| tree | 115e7af89ed5a83ed5433bbc5d306a4e263fdbd1 /src/client | |
| parent | f1af8679481cfc4199b6423d723f67188145ea46 (diff) | |
| download | BT-Programming-Assignment-435ffba7c3005e643a8d6f7fed54d0f556ee2ad7.tar.gz BT-Programming-Assignment-435ffba7c3005e643a8d6f7fed54d0f556ee2ad7.zip | |
get response for every operation and print it
Diffstat (limited to 'src/client')
| -rw-r--r-- | src/client/client.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp index d88df5f..6f6f152 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -25,6 +25,7 @@ void Client::start_client() while (true) { char operation; int k, v; + int index = -1; std::cout << "Choose the operation (i: Insert, g: Get, r: Remove, p: Print, e: Exit)" << '\n'; std::cin >> operation; @@ -39,7 +40,7 @@ void Client::start_client() std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); break; }; - send_request( + index = send_request( shared_memory, INSERT, std::optional(serialize(k)), std::optional(serialize(v))); break; case 'g': { @@ -50,9 +51,7 @@ void Client::start_client() std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); break; }; - int index = send_request(shared_memory, GET, std::optional(serialize(k)), std::nullopt); - std::string response = process_result(shared_memory, index); - std::cout << "Got: " << response << '\n'; + index = send_request(shared_memory, GET, std::optional(serialize(k)), std::nullopt); break; } case 'r': @@ -63,14 +62,19 @@ void Client::start_client() std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); break; }; - send_request(shared_memory, DELETE, std::optional(serialize(k)), std::nullopt); + index = send_request(shared_memory, DELETE, std::optional(serialize(k)), std::nullopt); break; case 'p': - send_request(shared_memory, PRINT, std::nullopt, std::nullopt); + index = send_request(shared_memory, PRINT, std::nullopt, std::nullopt); break; default: break; } + + if (index != -1) { + std::string response = process_result(shared_memory, index); + std::cout << response << '\n'; + } std::cout << '\n'; } } @@ -123,6 +127,7 @@ int Client::send_request( std::string Client::process_result(SharedMemory* shared_memory, int index) { + std::cout << "process result" << '\n'; pthread_mutex_lock(&shared_memory->mutex); while (!request_processed(shared_memory, index)) { |