-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRecvFile.cpp
More file actions
64 lines (55 loc) · 1.07 KB
/
Copy pathCRecvFile.cpp
File metadata and controls
64 lines (55 loc) · 1.07 KB
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
//#
#include "global.h"
#include "CMySocket.h"
#include "CServerTask.h"
int
main(int argc, char **argv)
{
using namespace MySocket;
int listenfd, connfd;
pid_t childpid;
void sig_chld(int), sig_int(int), web_child(int);
if (argc == 1)
{
listenfd = TcpListen();
}
else if (argc == 2)
{
listenfd = TcpListen(atoi(argv[1]));
}
else
{
printf("usage: server [port]\n");
exit(-1);
}
signal(SIGCHLD, sig_chld);
signal(SIGINT, sig_int);
for ( ; ; ) {
if ( (connfd = TcpAccept(listenfd)) < 0) {
if (errno == EINTR)
continue; /* back to for() */
else
printf("accept error");
}
if ( (childpid = fork()) == 0) { /* child process */
close(listenfd); /* close listening socket */
printf("a connect\n");
//web_child(connfd); /* process request */
CServerTask serTask(connfd);
serTask.Run();
exit(0);
}
close(connfd); /* parent closes connected socket */
}
}
/* end serv01 */
/* include sigint */
void
sig_int(int signo)
{
//void pr_cpu_time(void);
printf("sig_int\n");
//pr_cpu_time();
exit(0);
}
/* end sigint */