while(1){FD_ZERO(&readfds);FD_SET(sockfd,&readfds);for(fd=0;fd<MAXSOCKFD;fd++)if(is_connected[fd]) FD_SET(fd,&readfds);//fcntl(sockfd, F_SETFL, O_NONBLOCK)实现了非阻塞接收信息,select()解决了终端的阻塞问题if(!(nready = select(MAXSOCKFD,&readfds,NULL,NULL,NULL)))continue;for(fd=0;fd<MAXSOCKFD;fd++){if(FD_ISSET(fd,&readfds)){if(sockfd == fd){if((newsockfd = accept (sockfd,&addr,&addr_len))<0)perror(“accept”);write(newsockfd,msg,sizeof(msg));is_connected[newsockfd] =1;printf(“cnnect from %s\n”,inet_ntoa(addr.sin_addr));}else{bzero(buffer,sizeof(buffer));if(read(fd,buffer,sizeof(buffer))<=0){printf(“connect closed.\n”);is_connected[fd]=0;close(fd);}elseprintf(“%s”,buffer);}if(--nready <= 0)break;}}}-----------------------------------------------------------------------FD_ZERO(&readfds);while(1){FD_SET(sockfd,&readfds);for(fd=0;fd<MAXSOCKFD;fd++)if(is_connected[fd]) FD_SET(fd,&readfds);//fcntl(sockfd, F_SETFL, O_NONBLOCK)实现了非阻塞接收信息,select()解决了终端的阻塞问题if(!(nready = select(MAXSOCKFD,&readfds,NULL,NULL,NULL)))continue;for(fd=0;fd<MAXSOCKFD;fd++){if(FD_ISSET(fd,&readfds)){if(sockfd == fd){if((newsockfd = accept (sockfd,&addr,&addr_len))<0)perror(“accept”);write(newsockfd,msg,sizeof(msg));is_connected[newsockfd] =1;printf(“cnnect from %s\n”,inet_ntoa(addr.sin_addr));}else{bzero(buffer,sizeof(buffer));if(read(fd,buffer,sizeof(buffer))<=0){printf(“connect closed.\n”);is_connected[fd]=0;FD_CLR(fd, readfds);close(fd);}elseprintf(“%s”,buffer);}if(--nready <= 0)break;}}}上面的代码将FD_ZERO放在循环里面,下面的代码将FD_ZERO放在外面,但是有FD_CLR。二者有什么不一样么?我咋觉得第二种效率更高?为什么设计良好的代码应该永远不使用FD_CLR,而且实际情况中它也确实很少被使用?