unix 域套接字 问题
25 int var;
26 var=fcntl(sockfd,F_GETFL,0);
27 if(var&O_NONBLOCK)
28 {
29 cout<<"O_NONBLOCK"<<endl;
30 }//判断是一个阻塞的套接字
31 while(1)
32 {
33 if((connfd=accept(sockfd,(SA*)&addr2,&len))<0)
34 {
35 perror("accept");
36 if(errno==EINTR)
37 {
38 cout<<errno<<endl;
39 continue;
40 }
41 return -1;
42 }
43 int pid;
44 pid=fork();
45 if(pid==0)
46 {
47 char recv1[1024];
48 close(sockfd);
49 recv(connfd,recv1,1024,0);
50 cout<<recv1<<endl;
51 close(connfd);
52 }
53 close(connfd);
54 }
struct sockaddr_un addr;
6 addr.sun_family=AF_LOCAL;
7 bzero(addr.sun_path,sizeof(addr));
8 strcpy(addr.sun_path,"a.sock");
9 int sockfd;
10 sockfd=socket(AF_LOCAL,SOCK_STREAM,0);
11 if(connect(sockfd,(SA*)&addr,sizeof(addr))<0)
12 {
13 perror("connect");
14 exit(-1);
15 }
16 send(sockfd,"aa",2,0);
17 close(sockfd);