if (s->tcp_nodelay) { if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof s->tcp_nodelay) == -1) { lerror("setsockopt"); close(fd); break; } }
static void accept_connection(struct server *s){	struct sockaddr_in sa_remote, sa_local;	int lsa, fd;	struct connection *cn, *cw;	do {		lsa = sizeof sa_remote;		fd = accept(s->fd, (struct sockaddr *) &sa_remote, &lsa);		if (fd == -1) {			if (errno != EAGAIN)				lerror("accept");			break;		}		s->naccepts++;#ifndef POLL		if (fd >= FD_SETSIZE) {			log_d("accept_connection: dropped fd %d past FD_SETSIZE", fd);			close(fd);			break;		}#endif		if (s->tcp_nodelay) {			if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &s->tcp_nodelay, sizeof s->tcp_nodelay) == -1) {				lerror("setsockopt");				close(fd);				break;			}		}		fcntl(fd, F_SETFD, FD_CLOEXEC);		fcntl(fd, F_SETFL, O_NONBLOCK);		lsa = sizeof sa_local;		if (getsockname(fd, (struct sockaddr *) &sa_local, &lsa) == -1) {			lerror("getsockname");			close(fd);			break;		}		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[%hu] dropped", inet_ntoa(sa_remote.sin_addr), ntohs(sa_remote.sin_port));			close(fd);		} else {			s->nhandled++;			cn->state = HC_ACTIVE;			cn->s = s;			cn->fd = fd;			cn->rfd = -1;			cn->peer = sa_remote;			cn->sock = sa_local;			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);}