当前位置: 技术问答>linux和unix
关于socket里FD_ISSET的使用问题
来源: 互联网 发布时间:2015-11-01
本文导语: 代码如下: int main() { int server_sockfd,client_sockfd; int server_len,client_len; struct sockaddr_in server_address; struct sockaddr_in client_address; int result; fd_set readfds, testfds; server_sockfd=socket(AF_INET,SOCK_STREAM,0); server_address.sin_famil...
代码如下:
int main()
{
int server_sockfd,client_sockfd;
int server_len,client_len;
struct sockaddr_in server_address;
struct sockaddr_in client_address;
int result;
fd_set readfds, testfds;
server_sockfd=socket(AF_INET,SOCK_STREAM,0);
server_address.sin_family=AF_INET;
server_address.sin_addr.s_addr=htonl(INADDR_ANY);
server_address.sin_port=htons(3333);
server_len=sizeof(server_address);
bind(server_sockfd,(struct sockaddr *)&server_address,server_len);
listen(server_sockfd,5);
FD_ZERO(&readfds);
FD_SET(server_sockfd,&readfds);
while(1)
{
char ch;
int fd;
int nread;
testfds=readfds;
printf("server waitingn");
result=select(FD_SETSIZE,&testfds,(fd_set *)0,(fd_set *)0,(struct timeval *)0);
if (result
int main()
{
int server_sockfd,client_sockfd;
int server_len,client_len;
struct sockaddr_in server_address;
struct sockaddr_in client_address;
int result;
fd_set readfds, testfds;
server_sockfd=socket(AF_INET,SOCK_STREAM,0);
server_address.sin_family=AF_INET;
server_address.sin_addr.s_addr=htonl(INADDR_ANY);
server_address.sin_port=htons(3333);
server_len=sizeof(server_address);
bind(server_sockfd,(struct sockaddr *)&server_address,server_len);
listen(server_sockfd,5);
FD_ZERO(&readfds);
FD_SET(server_sockfd,&readfds);
while(1)
{
char ch;
int fd;
int nread;
testfds=readfds;
printf("server waitingn");
result=select(FD_SETSIZE,&testfds,(fd_set *)0,(fd_set *)0,(struct timeval *)0);
if (result