- 论坛徽章:
- 0
|
参考一下 httpd0.5 中的做法:
#ifdef BSD
void ign() {
int status;
pid_t pid;
while( (pid = wait3(&status, WNOHANG, NULL)) > 0);
}
#endif
…………
while(1) {
retry:
clen=sizeof(sa_client);
if((csd=accept(sd,&sa_client,&clen)) == -1) {
if(errno == EINTR) {
#ifdef BSD
ign();
#endif
goto retry;
}
perror("accept");
server_error(stdout,SOCKET_ACCEPT);
}
if((pid = fork()) == -1)
server_error(stdout,FORK);
else if(!pid) {
close(0);
close(1);
dup2(csd,0);
dup2(csd,1);
close(sd);
process_request(stdin,stdout);
fclose(stdin);
fclose(stdout);
exit(0);
}
close(csd);
} |
|