--- festival/src/arch/festival/server.cc.orig 2006-03-07 15:47:37.000000000 +0100 +++ festival/src/arch/festival/server.cc 2006-03-07 15:50:04.000000000 +0100 @@ -148,49 +148,65 @@ int festival_start_server(int port) while(1) // never exits except by signals { - if((fd1 = accept(fd, 0, 0)) < 0) - { - cerr << "socket: accept failed"; - festival_error(); - } +#ifndef SINGLE_CLIENT + struct timeval timeout; + timeout.tv_sec = 10L; // 10 second timeout + timeout.tv_usec = 0L; + + fd_set fds; + FD_ZERO(&fds); + FD_SET(fd, &fds); - client_name++; - if (client_access_check(fd1,client_name) == FALSE) + if(select(fd + 1, &fds, NULL, NULL, &timeout) > 0) // fd has changed, process request { - close(fd1); - continue; - } +#endif + if((fd1 = accept(fd, 0, 0)) < 0) + { + cerr << "socket: accept failed"; + festival_error(); + } + + client_name++; + if (client_access_check(fd1,client_name) == FALSE) + { + close(fd1); + continue; + } #ifdef SINGLE_CLIENT - ft_server_socket = fd1; - repl_from_socket(fd1); - log_message(client_name,"disconnected"); -#else - num_clients++; - - // Fork new image of festival and call interpreter - if (num_clients > max_clients) - { - log_message(client_name,"failed: too many clients"); - num_clients--; - } - else if ((pid=fork()) == 0) - { ft_server_socket = fd1; repl_from_socket(fd1); log_message(client_name,"disconnected"); - exit(0); - } - else if (pid < 0) - { - log_message(client_name,"failed to fork new client"); - num_clients--; + close(fd1); +#else + num_clients++; + + // Fork new image of festival and call interpreter + if (num_clients > max_clients) + { + log_message(client_name,"failed: too many clients"); + num_clients--; + close(fd1); + } + else if ((pid=fork()) == 0) + { + ft_server_socket = fd1; + repl_from_socket(fd1); + log_message(client_name,"disconnected"); + close(fd1); + exit(0); + } + else if (pid < 0) + { + log_message(client_name,"failed to fork new client"); + num_clients--; + close(fd1); + } } - while (waitpid(0,&statusp,WNOHANG) != 0) + while (waitpid(0,&statusp,WNOHANG) > 0) num_clients--; -#endif - close(fd1); +#endif } return 0;