-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
76 lines (51 loc) · 1.3 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <sys/wait.h>
#include "Server.h"
#include "Worker.h"
extern int errno;
int main() {
bool exit = false;
bool start = true;
int listenfd = CreateServer();
WorkerManage workerManage;
int workers = 0;
while (!exit) {
pid_t pid = workerManage.CreateWorkers(WORKERS - workers);
if (pid == 0) {
//worker
worker(listenfd, workerManage.getfd());
//exit= true;
//exit(0);
return 0;
} else {
//master
//signal(0,SIGIO,input);
if (start) {
start = false;
std::thread thread([&]() {
char c;
while ((c = getchar()) != 'q') {
}
exit = true;
workerManage.CloseWorkers();
});
thread.detach();
}
workers = WORKERS;
int t = 0;
int status = 0;
t = waitpid(-1, &status, 0);
if (t < 0) {
workers = 0;
} else {
workers--;
}
}
}
close(listenfd);
std::cout << "exit" << std::endl;
/*if (setuid(uid)) {
perror("");
}*/
return 0;
}