while (1) {
    fd_set listen_fds = all_fds;
    if (select(max_fd + 1, &listen_fds, NULL, NULL, NULL) == -1) {
        perror("server: select");
        exit(1);
    }

    if (FD_ISSET(sock_fd, &listen_fds)) {
        int client_fd = accept_connection(sock_fd, users);
        if (client_fd > max_fd) {
            max_fd = client_fd;
        }
        FD_SET(client_fd, &all_fds);
        printf("Accepted connection\n");
    }

    for (int index = 0; index < MAX_CONNECTIONS; index++) {
        if (users[index].sock_fd > -1 && FD_ISSET(users[index].sock_fd, &listen_fds)) {
            int client_closed = read_from(index, users);
            if (client_closed > 0) {
                FD_CLR(client_closed, &all_fds);
                printf("Client %d disconnected\n", client_closed);
            } else {
                printf("Echoing message from client %d\n", users[index].sock_fd);
            }
        }
    }
