about summary refs log tree commit diff stats
path: root/src/server/main.cpp
blob: 631546051f2372f586c62df48f992296673a5d72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <csignal>
#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <string>

#include "shared_memory_server.h"

Server<int, int> shm;

/**
 * @brief Shuts the server down, when pressing <Ctrl+C>.
 *
 * @param signal Specifies the signal, which was caught.
 */
void signal_handler(int signal) {
    if (signal == SIGINT) {
        std::cout << "Server shutting down" << '\n';
        exit(0);
    }
}

int main(int argc, char* argv[])
{
    if (argc != 2) {
        std::cout << "Usage: " << argv[0] << " <number-of-buckets>\n";
        return 1;
    }

    uint32_t size;
    try {
        size = std::stoi(std::string(argv[1]));
    } catch (const std::invalid_argument& e) {
        std::cout << "Invalid argument" << '\n';
        return 1;
    }

    shm.initialize_hashtable(size);

    std::signal(SIGINT, signal_handler);

    shm.process_requests();

    return 0;
}