-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
46 lines (41 loc) · 957 Bytes
/
main.cpp
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
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <string.h>
#include <string>
#include <poll.h>
#include <sstream>
#include <signal.h>
#include <cstdlib>
#include "server.hpp"
void signalHandler(int sig) {
std::cout << "Attempting Quit Server" << std::endl;
if (sig == SIGINT)
{
Server::_active = false;
signal(SIGINT, SIG_IGN);
}
std::cout << "Quit Server" << std::endl;
}
int main(int argc, char** argv)
{
if (argc != 3)
{
std::cout << "Please enter the right amount of arguments" << std::endl;
return (0);
}
int port = atoi(argv[1]);
std::string serverPass(argv[2]);
Server ourServer(serverPass, port);
ourServer.createServer();
signal(SIGINT, signalHandler);
ourServer.initClient();
ourServer.clients[0].fd = ourServer.fd_server;
ourServer.clients[0].events = POLLIN;
ourServer.pollLoop();
close(ourServer.fd_server);
return (0);
}