Linux?μ?socket???С???????
???????????? ???????[ 2014/10/30 11:24:08 ] ????????Linux ???? ??????
????????unix????????о????????????飬????????????????????£??????С??????????????????????£?????????????????????????????????????????????????????????????^_^
????????????????????С???·????????в?????·????????簢????????^_^
?????????????????tcp?? C/S .?????????( ???????£??????????????????????????????????????????г??? ????????????????????????? )??
???????????????????
1 #ifndef MYLIB_H
2 #define MYLIB_H
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <netinet/in.h>
7 #include <sys/socket.h>
8 #include <arpa/inet.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <errno.h>
12 #include <signal.h>
13 #include <sys/wait.h>
14
15 #define LISTENQ 1024
16 #define MAXLINE 1460
17 #define SERV_PORT 9877
18
19 typedef void (*SignalFunc)(int);
20
21 SignalFunc signal(int sigNo??SignalFunc fun);
22 void sig_chld(int sigNo);
23 void sys_err(char *pa);
24
25 #endif // MYLIB_H
??????Щ??????????????Щ???壬???????????????????????????????????????????mylib.h ??
?????????????????£?
????1??signal ?????????????????????????????????????????????
????2??sig_chld ??signal???????????????
????3??sys_err ?????????????????????
?????±?????????????????????????????????????????????????????????
1 #include <mylib.h>
2
3 void sys_err(char *pa)
4 {
5 printf("%s"??pa);
6 exit(1);
7 }
8
9 SignalFunc signal(int sigNo?? SignalFunc fun){
10 struct sigaction act ?? oact;
11 act.sa_handler=fun;
12 sigemptyset(&act.sa_mask); //Additional set of signals to be blocked.
13 act.sa_flags=0;
14 if(sigaction(sigNo??&act??&oact)<0)
15 return SIG_ERR;
16 return oact.sa_handler;
17 }
18
19 void sig_chld(int sigNo)
20 {
21 pid_t pid;
22 int state;
23 while ((pid=waitpid(-1??&state??WNOHANG))>0) {
24 printf("process %d terminated
"??pid);
25 }
26 return;
27 }
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11