rv = close(fd); if (debug) log_d("accept_connection: close(%d) = %d", fd, rv);
close(fd);
static void accept_connection(struct server *s){	struct sockaddr_in sa;	int lsa, fd, rv;	struct connection *cn, *cw;	do {		lsa = sizeof sa;		fd = accept(s->fd, (struct sockaddr *) &sa, &lsa);		if (debug) {			if (fd == -1)				log_d("accept_connection: accept(%d) = %d", s->fd, fd);			else				log_d("accept_connection: accept(%d) = %d; addr=[%s], port=%d",					s->fd, fd, inet_ntoa(sa.sin_addr), htons(sa.sin_port));		}		if (fd == -1) {			if (errno != EAGAIN)				lerror("accept");			break;		}		s->naccepts++;		rv = fcntl(fd, F_SETFD, FD_CLOEXEC);		if (debug)			log_d("accept_connection: fcntl(%d, F_SETFD, FD_CLOEXEC) = %d", fd, rv);		rv = fcntl(fd, F_SETFL, O_NONBLOCK);		if (debug)			log_d("accept_connection: fcntl(%d, F_SETFL, O_NONBLOCK) = %d", fd, rv);		cn = connections;		cw = 0;		while (cn) {			if (cn->state == HC_FREE)				break;			if (cw == 0 && cn->action == HC_WAITING)				cw = cn;			cn = cn->next;		}		if (cn == 0 && cw) {			close_connection(cw);			cn = cw;		}		if (cn == 0) {			log_d("connection to %s dropped", inet_ntoa(sa.sin_addr));			rv = close(fd);			if (debug)				log_d("accept_connection: close(%d) = %d", fd, rv);		} else {			s->nhandled++;			cn->state = HC_ACTIVE;			cn->s = s;			cn->fd = fd;			cn->rfd = -1;			cn->peer = sa;			strncpy(cn->ip, inet_ntoa(sa.sin_addr), 15);			cn->t = cn->it = current_time;			++nconnections;			if (nconnections > maxconnections)				maxconnections = nconnections;			init_connection(cn);			cn->logged = 0;			cn->action = HC_READING;		}	} while (tuning.accept_multi);}