old version
FD_ZERO(&rfds);
FD_ZERO(&master);
FD_SET(sockserver, &master);
fdmax = sockserver;
for(;;) {
rfds = master;
if( select(fdmax+1, &rfds, NULL, NULL, NULL) == -1) {
perror("select");
exit(1);
}
new version
FD_ZERO(&rfds);
FD_ZERO(&master);
FD_SET(sockserver, &master);
fdmax = sockserver;
for(;;) {
FD_ZERO(&rfds);
for(j=0;j<max_socket;j++){
if(FD_ISSET(j,&master))
FD_SET(j,&rfds);
}
/* Not copying directly, because you can't assume that the set is integer type.
It may be anything. */
if( select(fdmax+1, &rfds, NULL, NULL, NULL) == -1) {
perror("select");
exit(1);
}
I tried old version and will crash when run to select(), then I searched new version and try, it's still crash. I also tried to move out all local variables that I thought it might be stack overflow, but it still crash.
Can someone answer this problem? Thanks a lot.