-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cpp
More file actions
52 lines (42 loc) · 893 Bytes
/
server.cpp
File metadata and controls
52 lines (42 loc) · 893 Bytes
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
46
47
48
49
50
51
52
#include <string>
#include <signal.h>
#include "include/server/server.hpp"
Server *server_ptr;
void closeServer(int s)
{
server_ptr->closeServer();
}
int printUsage()
{
std::cout << "Usage: ./server num_of_clients [port]" << std::endl;
exit(1);
}
int main(int argc, char const *argv[])
{
// signal(SIGINT, closeServer);
// // struct sigaction sigIntHandler;
// // sigIntHandler.sa_handler = closeServer;
// // sigemptyset(&sigIntHandler.sa_mask);
// // sigIntHandler.sa_flags = 0;
// // sigaction(SIGINT, &sigIntHandler, NULL);
int port, clients;
// Input parsing
if (argc < 2 || argc > 3)
{
printUsage();
}
// Define default port
port = (argc == 2) ? 8000 : std::stoi(argv[2]);
clients = std::stoi(argv[1]);
try
{
Server server(clients, port);
server_ptr = &server;
}
catch (const char* msg)
{
std::cerr << msg << std::endl;
return 1;
}
return 0;
}