I'm trying to wrap my head around calling select on sockets and I can't understand what I'm doing wrong.
setup_server_socket calls bind and listen and sets the socket to nonblocking mode.
The following code blocks on the select call it seems, not moving forward to FD_ISSET. I tried connecting a client and it seems to succeed but select never returns anything.
What's the proper way to do this?
...
int listenfd = setup_server_socket( serverPort );
if( -1 == listenfd )
return 1;
fd_set read_fds;
FD_ZERO(&read_fds);
int fdmax = listenfd;
// loop forever
while( 1 )
{
if (select(fdmax+1, &read_fds, NULL,NULL,NULL) == -1){
perror("select");
exit(4);
}
for (int i = 0; i<= fdmax; i++){
printf("Testing: %d, %d\n", i, FD_ISSET(i,&read_fds));
}return 0;
...