- int fd, ret = para_accept(ss->listen_fd, NULL, 0);
- if (ret < 0) {
- PARA_ERROR_LOG("%s\n", para_strerror(-ret));
- return NULL;
+ int fd, ret;
+ unsigned n;
+
+ FOR_EACH_LISTEN_FD(n, ss) {
+ if (ss->listen_fds[n] < 0)
+ continue;
+ ret = para_accept(ss->listen_fds[n], rfds, NULL, 0, &fd);
+ if (ret < 0)
+ goto warn;
+ if (ret == 0)
+ continue;
+ ret = -E_MAX_CLIENTS;
+ if (ss->max_clients > 0 && ss->num_clients >= ss->max_clients)
+ goto close_fd_and_warn;
+ ret = mark_fd_nonblocking(fd);
+ if (ret < 0)
+ goto close_fd_and_warn;
+ ret = acl_check_access(fd, &ss->acl, ss->default_deny);
+ if (ret < 0)
+ goto close_fd_and_warn;
+ ss->num_clients++;
+ sc = para_calloc(sizeof(*sc));
+ sc->fd = fd;
+ sc->name = para_strdup(remote_name(fd));
+ sc->cq = cq_new(MAX_CQ_BYTES);
+ para_list_add(&sc->node, &ss->client_list);
+ add_close_on_fork_list(fd);
+ PARA_INFO_LOG("accepted client #%d: %s (fd %d)\n", ss->num_clients,
+ sc->name, fd);
+ return sc;
+close_fd_and_warn:
+ close(fd);
+warn:
+ PARA_WARNING_LOG("%s\n", para_strerror(-ret));