another version, behaves better under stress

This commit is contained in:
Anselm R Garbe 2009-08-15 22:25:22 +01:00
parent c05e00039f
commit 5dfc25167d

View file

@ -300,7 +300,6 @@ request(void) {
void void
serve(int fd) { serve(int fd) {
int result; int result;
unsigned int timeout = 1;
socklen_t salen; socklen_t salen;
struct sockaddr sa; struct sockaddr sa;
@ -308,8 +307,8 @@ serve(int fd) {
while(running) { while(running) {
if((cfd = accept(fd, &sa, &salen)) == -1) { if((cfd = accept(fd, &sa, &salen)) == -1) {
/* el cheapo socket release */ /* el cheapo socket release */
fprintf(stderr, "%s: cannot accept(), sleep %u seconds\n", tstamp(), timeout); fprintf(stderr, "%s: cannot accept: %s, sleep a second...\n", tstamp(), strerror(errno));
sleep(timeout++); sleep(1);
continue; continue;
} }
if(fork() == 0) { if(fork() == 0) {
@ -324,7 +323,6 @@ serve(int fd) {
close(cfd); close(cfd);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
timeout = 1;
} }
fprintf(stdout, "%s: shutting down\n", tstamp()); fprintf(stdout, "%s: shutting down\n", tstamp());
} }