-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.cpp
More file actions
46 lines (33 loc) · 953 Bytes
/
server.cpp
File metadata and controls
46 lines (33 loc) · 953 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
#include "server.h"
#include <cstdlib>
#include <signal.h>
#include <iostream>
// The current Server
static OmpServer* ServerToClose = 0;
// Ctr + c => stop the server
void stopServerSignal(int){
if( ServerToClose ){ //if there is a server running
ServerToClose->stopRun();
}
}
int main(int argc, char *argv[]){
if (argc < 2) {
std::cerr<<" No port provided\n";
exit(0);
}
// Install Signal handler
if( signal(SIGINT , stopServerSignal) == SIG_ERR ){
std::cout << "Error cannot install signal handler..." << std::endl;
return 56;
}
std::cout << "Press Ctr + C to stop..." << std::endl;
//get port from user
int portno = atoi(argv[1]);
// Create and run the server & pass port to server
OmpServer server(portno);
ServerToClose = &server;
server.run();
// Remove the ugly ^C
std::cout << "\r";
return 0;
}