-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
61 lines (49 loc) · 1.06 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
#include "handle.h"
#include "lib.h"
#include <sys/wait.h>
using namespace std;
int mkline(int LineSize=100, char ch='*'){
cout << "\n";
for (int j=0; j < LineSize; j++) cout << ch ;
cout << "\n";
return 0;
};
int main(int argc, char* argv[])
{
int pid,keep=1, status;
char Answer='Y';
mkline();
try {
MyServerSocket sock;
ReqHandle handler;
BaseSocket * pConn = NULL;
cout << "Accept new connection? (Y/N)" << endl;
cin >> Answer;
(Answer=='Y' || Answer=='y') ? keep=1 : keep=0;
while (keep){
pConn = sock.Accept();
switch (pid=fork()){
// case -1:
// delete pConn;
// throw (SocketException(SocketException::ESE_FORK));
case 0:
handler.ParseRequest(pConn);
cout << "\n--RESPONSE--\n" << endl;
handler.MakeResponse(pConn);
delete pConn;
return 0;
default:
wait(&status);
delete pConn;
cout << "Accept new connection? (Y/N)" << endl;
cin >> Answer;
(Answer=='Y' || Answer=='y') ? keep=1 : keep=0;
};
};
}
catch (Exception& e){
e.Report();
};
mkline();
return 0;
}