From ad37397a4f7734394ef1f03b4b54a54226421a4e Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 30 Sep 2021 22:18:43 +0200 Subject: [PATCH] net: Drop fd_set parameter from para_accept(). As for read_nonblock(), the parameter is dispensable because it is only used for an optimization to avoid a system call. Get rid of it because it hinders the conversion from select(2) to poll(2). --- afs.c | 2 +- audiod.c | 2 +- audiod.h | 2 +- audiod_command.c | 5 ++--- dccp_send.c | 4 ++-- http_send.c | 4 ++-- net.c | 8 ++------ net.h | 2 +- send.h | 2 +- send_common.c | 5 ++--- server.c | 2 +- 11 files changed, 16 insertions(+), 22 deletions(-) diff --git a/afs.c b/afs.c index c2081db7..9f32c8aa 100644 --- a/afs.c +++ b/afs.c @@ -948,7 +948,7 @@ static int command_post_select(struct sched *s, void *context) free(client); } /* Accept connections on the local socket. */ - ret = para_accept(ct->fd, &s->rfds, &unix_addr, sizeof(unix_addr), &fd); + ret = para_accept(ct->fd, &unix_addr, sizeof(unix_addr), &fd); if (ret < 0) PARA_NOTICE_LOG("%s\n", para_strerror(-ret)); if (ret <= 0) diff --git a/audiod.c b/audiod.c index 482cce37..693c031a 100644 --- a/audiod.c +++ b/audiod.c @@ -1092,7 +1092,7 @@ static int command_post_select(struct sched *s, void *context) ret = task_get_notification(ct->task); if (ret < 0) return ret; - ret = handle_connect(ct->fd, &s->rfds); + ret = handle_connect(ct->fd); if (ret < 0) { PARA_NOTICE_LOG("%s\n", para_strerror(-ret)); if (ret == -E_AUDIOD_TERM) { diff --git a/audiod.h b/audiod.h index b40fdd67..18fb75b3 100644 --- a/audiod.h +++ b/audiod.h @@ -21,5 +21,5 @@ bool uid_is_whitelisted(uid_t uid); /* defined in audiod_command.c */ void audiod_status_dump(bool force); void close_stat_clients(void); -int handle_connect(int accept_fd, fd_set *rfds); +int handle_connect(int accept_fd); void stat_client_write_item(int item_num); diff --git a/audiod_command.c b/audiod_command.c index bb54dfab..19537cf0 100644 --- a/audiod_command.c +++ b/audiod_command.c @@ -360,7 +360,6 @@ EXPORT_AUDIOD_CMD_HANDLER(version) * Handle arriving connections on the local socket. * * \param accept_fd The fd to accept connections on. - * \param rfds If \a accept_fd is not set in \a rfds, do nothing. * * This is called in each iteration of the select loop. If there is an incoming * connection on \a accept_fd, this function reads the command sent by the peer, @@ -373,7 +372,7 @@ EXPORT_AUDIOD_CMD_HANDLER(version) * * \sa \ref para_accept(), \ref recv_cred_buffer(). * */ -int handle_connect(int accept_fd, fd_set *rfds) +int handle_connect(int accept_fd) { int argc, ret, clifd; char buf[MAXLINE], **argv = NULL; @@ -384,7 +383,7 @@ int handle_connect(int accept_fd, fd_set *rfds) char *errctx = NULL; const struct audiod_command_info *aci; - ret = para_accept(accept_fd, rfds, &unix_addr, sizeof(struct sockaddr_un), &clifd); + ret = para_accept(accept_fd, &unix_addr, sizeof(struct sockaddr_un), &clifd); if (ret <= 0) return ret; ret = recv_cred_buffer(clifd, buf, sizeof(buf) - 1); diff --git a/dccp_send.c b/dccp_send.c index bca7ad67..5806bce3 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -119,14 +119,14 @@ static void dccp_send_fec(struct sender_client *sc, char *buf, size_t len) dccp_shutdown_client(sc); } -static void dccp_post_select(fd_set *rfds, __a_unused fd_set *wfds) +static void dccp_post_select(__a_unused fd_set *rfds, __a_unused fd_set *wfds) { struct sender_client *sc; struct dccp_fec_client *dfc; int tx_ccid; uint32_t k, n; - sc = accept_sender_client(dss, rfds); + sc = accept_sender_client(dss); if (!sc) return; diff --git a/http_send.c b/http_send.c index 987145bf..39ef05a1 100644 --- a/http_send.c +++ b/http_send.c @@ -158,7 +158,7 @@ static void http_send(long unsigned current_chunk, } } -static void http_post_select(fd_set *rfds, __a_unused fd_set *wfds) +static void http_post_select(__a_unused fd_set *rfds, __a_unused fd_set *wfds) { struct sender_client *sc, *tmp; struct private_http_sender_data *phsd; @@ -188,7 +188,7 @@ static void http_post_select(fd_set *rfds, __a_unused fd_set *wfds) break; } } - sc = accept_sender_client(hss, rfds); + sc = accept_sender_client(hss); if (!sc) return; phsd = para_malloc(sizeof(*phsd)); diff --git a/net.c b/net.c index e1951e5e..4a6f9a63 100644 --- a/net.c +++ b/net.c @@ -801,25 +801,21 @@ int recv_buffer(int fd, char *buf, size_t size) * Wrapper around the accept system call. * * \param fd The listening socket. - * \param rfds An optional fd_set pointer. * \param addr Structure which is filled in with the address of the peer socket. * \param size Should contain the size of the structure pointed to by \a addr. * \param new_fd Result pointer. * - * Accept incoming connections on \a addr, retry if interrupted. If \a rfds is - * not \p NULL, return 0 if \a fd is not set in \a rfds without calling accept(). + * Accept incoming connections on addr, retry if interrupted. * * \return Negative on errors, zero if no connections are present to be accepted, * one otherwise. * * \sa accept(2). */ -int para_accept(int fd, fd_set *rfds, void *addr, socklen_t size, int *new_fd) +int para_accept(int fd, void *addr, socklen_t size, int *new_fd) { int ret; - if (rfds && !FD_ISSET(fd, rfds)) - return 0; do ret = accept(fd, (struct sockaddr *) addr, &size); while (ret < 0 && errno == EINTR); diff --git a/net.h b/net.h index 2256f376..fd89dc5d 100644 --- a/net.h +++ b/net.h @@ -143,7 +143,7 @@ extern int generic_max_transport_msg_size(int sockfd); int recv_bin_buffer(int fd, char *buf, size_t size); int recv_buffer(int fd, char *buf, size_t size); -int para_accept(int fd, fd_set *rfds, void *addr, socklen_t size, int *new_fd); +int para_accept(int fd, void *addr, socklen_t size, int *new_fd); int create_local_socket(const char *name); int connect_local_socket(const char *name); int recv_cred_buffer(int, char *, size_t); diff --git a/send.h b/send.h index f6aafbb4..9eda2a17 100644 --- a/send.h +++ b/send.h @@ -222,6 +222,6 @@ void generic_com_on(struct sender_status *ss, unsigned protocol); void generic_acl_deplete(struct list_head *acl); void generic_com_off(struct sender_status *ss); char *generic_sender_help(void); -struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfds); +struct sender_client *accept_sender_client(struct sender_status *ss); int send_queued_chunks(int fd, struct chunk_queue *cq); int parse_fec_url(const char *arg, struct sender_command_data *scd); diff --git a/send_common.c b/send_common.c index 90242d5c..227a3eb8 100644 --- a/send_common.c +++ b/send_common.c @@ -343,7 +343,6 @@ void generic_com_off(struct sender_status *ss) * Accept a connection on the socket(s) this server is listening on. * * \param ss The sender whose listening fd is ready for reading. - * \param rfds Passed to para_accept(), * * This accepts incoming connections on any of the listening sockets of the * server. If there is a connection pending, the function @@ -367,7 +366,7 @@ void generic_com_off(struct sender_status *ss) * \sa \ref para_accept(), \ref mark_fd_nonblocking(), \ref acl_check_access(), * \ref cq_new(), \ref add_close_on_fork_list(). */ -struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfds) +struct sender_client *accept_sender_client(struct sender_status *ss) { struct sender_client *sc; int fd, ret; @@ -376,7 +375,7 @@ struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfd FOR_EACH_LISTEN_FD(n, ss) { if (ss->listen_fds[n] < 0) continue; - ret = para_accept(ss->listen_fds[n], rfds, NULL, 0, &fd); + ret = para_accept(ss->listen_fds[n], NULL, 0, &fd); if (ret < 0) goto warn; if (ret == 0) diff --git a/server.c b/server.c index 8c0dc44f..ce4ebf34 100644 --- a/server.c +++ b/server.c @@ -337,7 +337,7 @@ static int command_task_accept(unsigned listen_idx, struct sched *s, pid_t child_pid; uint32_t *chunk_table; - ret = para_accept(sct->listen_fds[listen_idx], &s->rfds, NULL, 0, &new_fd); + ret = para_accept(sct->listen_fds[listen_idx], NULL, 0, &new_fd); if (ret <= 0) goto out; mmd->num_connects++; -- 2.39.2