From e854df2fe2cfb3ae90a439828fc13cc0fc470aa9 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 3 Oct 2021 21:37:40 +0200 Subject: [PATCH] send: Avoid select-specific arguments in {pre,post}_select(). Just pass a pointer to struct sched instead of the fd sets. Since two of the prototypes declared in send.h now refer to this structure, sched.h must be included before send.h. The udp sender implements neither ->pre_select() nor ->post_select(), so we only need to fix the order in which send.h and sched.h are included. --- command.c | 2 +- dccp_send.c | 9 ++++----- http_send.c | 12 ++++++------ send.h | 17 +++++++---------- send_common.c | 2 +- server.c | 2 +- udp_send.c | 2 +- vss.c | 6 +++--- 8 files changed, 24 insertions(+), 28 deletions(-) diff --git a/command.c b/command.c index e3f12931..200ff054 100644 --- a/command.c +++ b/command.c @@ -22,8 +22,8 @@ #include "net.h" #include "server.h" #include "list.h" -#include "send.h" #include "sched.h" +#include "send.h" #include "vss.h" #include "daemon.h" #include "fd.h" diff --git a/dccp_send.c b/dccp_send.c index 5806bce3..47d6b408 100644 --- a/dccp_send.c +++ b/dccp_send.c @@ -24,8 +24,8 @@ #include "net.h" #include "server.h" #include "list.h" -#include "send.h" #include "sched.h" +#include "send.h" #include "vss.h" #include "fd.h" @@ -36,14 +36,13 @@ struct dccp_fec_client { struct fec_client *fc; }; -static void dccp_pre_select(int *max_fileno, fd_set *rfds, - __a_unused fd_set *wfds) +static void dccp_pre_select(struct sched *s) { unsigned n; FOR_EACH_LISTEN_FD(n, dss) if (dss->listen_fds[n] >= 0) - para_fd_set(dss->listen_fds[n], rfds, max_fileno); + para_fd_set(dss->listen_fds[n], &s->rfds, &s->max_fileno); } /** @@ -119,7 +118,7 @@ static void dccp_send_fec(struct sender_client *sc, char *buf, size_t len) dccp_shutdown_client(sc); } -static void dccp_post_select(__a_unused fd_set *rfds, __a_unused fd_set *wfds) +static void dccp_post_select(__a_unused struct sched *s) { struct sender_client *sc; struct dccp_fec_client *dfc; diff --git a/http_send.c b/http_send.c index 39ef05a1..6d026c71 100644 --- a/http_send.c +++ b/http_send.c @@ -20,8 +20,8 @@ #include "server.h" #include "http.h" #include "list.h" -#include "send.h" #include "sched.h" +#include "send.h" #include "vss.h" #include "close_on_fork.h" #include "fd.h" @@ -158,7 +158,7 @@ static void http_send(long unsigned current_chunk, } } -static void http_post_select(__a_unused fd_set *rfds, __a_unused fd_set *wfds) +static void http_post_select(__a_unused struct sched *s) { struct sender_client *sc, *tmp; struct private_http_sender_data *phsd; @@ -196,7 +196,7 @@ static void http_post_select(__a_unused fd_set *rfds, __a_unused fd_set *wfds) phsd->status = HTTP_CONNECTED; } -static void http_pre_select(int *max_fileno, fd_set *rfds, fd_set *wfds) +static void http_pre_select(struct sched *s) { struct sender_client *sc, *tmp; unsigned n; @@ -204,15 +204,15 @@ static void http_pre_select(int *max_fileno, fd_set *rfds, fd_set *wfds) FOR_EACH_LISTEN_FD(n, hss) { if (hss->listen_fds[n] < 0) continue; - para_fd_set(hss->listen_fds[n], rfds, max_fileno); + para_fd_set(hss->listen_fds[n], &s->rfds, &s->max_fileno); } list_for_each_entry_safe(sc, tmp, &hss->client_list, node) { struct private_http_sender_data *phsd = sc->private_data; if (phsd->status == HTTP_CONNECTED) /* need to recv get request */ - para_fd_set(sc->fd, rfds, max_fileno); + para_fd_set(sc->fd, &s->rfds, &s->max_fileno); if (phsd->status == HTTP_GOT_GET_REQUEST || phsd->status == HTTP_INVALID_GET_REQUEST) - para_fd_set(sc->fd, wfds, max_fileno); + para_fd_set(sc->fd, &s->wfds, &s->max_fileno); } } diff --git a/send.h b/send.h index 9eda2a17..1d9db37e 100644 --- a/send.h +++ b/send.h @@ -80,23 +80,20 @@ struct sender { * Add file descriptors to fd_sets. * * The pre_select function of each supported sender is called just before - * para_server enters its main select loop. Each sender may add its own - * file descriptors to the \a rfds or the \a wfds set. - * - * If a file descriptor was added, \a max_fileno must be increased by - * this function, if necessary. + * para_server enters its main select loop. Each sender may watch its own + * file descriptors for reading or writing. * * \sa select(2). */ - void (*pre_select)(int *max_fileno, fd_set *rfds, fd_set *wfds); + void (*pre_select)(struct sched *s); /** * Handle the file descriptors which are ready for I/O. * - * If the pre_select hook added one ore more file descriptors to the - * read or write set, this is the hook to check the result and do any - * I/O on those descriptors which are ready for reading/writing. + * If the pre_select hook asked for one or more file descriptors to be + * watched, this is the hook to check the result and perform I/O on the + * descriptors which are ready for reading/writing. */ - void (*post_select)(fd_set *rfds, fd_set *wfds); + void (*post_select)(struct sched *s); /** * Terminate all connected clients. * diff --git a/send_common.c b/send_common.c index 227a3eb8..ce167542 100644 --- a/send_common.c +++ b/send_common.c @@ -21,10 +21,10 @@ #include "afs.h" #include "server.h" #include "acl.h" +#include "sched.h" #include "send.h" #include "close_on_fork.h" #include "chunk_queue.h" -#include "sched.h" #include "vss.h" /** Clients will be kicked if there are more than that many bytes pending. */ diff --git a/server.c b/server.c index ce4ebf34..ca00d0e9 100644 --- a/server.c +++ b/server.c @@ -24,8 +24,8 @@ #include "net.h" #include "server.h" #include "list.h" -#include "send.h" #include "sched.h" +#include "send.h" #include "vss.h" #include "config.h" #include "close_on_fork.h" diff --git a/udp_send.c b/udp_send.c index 68d75e3c..ac656ff2 100644 --- a/udp_send.c +++ b/udp_send.c @@ -21,8 +21,8 @@ #include "net.h" #include "server.h" #include "list.h" -#include "send.h" #include "sched.h" +#include "send.h" #include "vss.h" #include "portable_io.h" #include "fd.h" diff --git a/vss.c b/vss.c index 23b64abb..d2fbfb34 100644 --- a/vss.c +++ b/vss.c @@ -28,8 +28,8 @@ #include "net.h" #include "server.h" #include "list.h" -#include "send.h" #include "sched.h" +#include "send.h" #include "vss.h" #include "ipc.h" #include "fd.h" @@ -906,7 +906,7 @@ static void vss_pre_select(struct sched *s, void *context) FOR_EACH_SENDER(i) { if (!senders[i]->pre_select) continue; - senders[i]->pre_select(&s->max_fileno, &s->rfds, &s->wfds); + senders[i]->pre_select(s); } vss_compute_timeout(s, vsst); } @@ -1149,7 +1149,7 @@ static int vss_post_select(struct sched *s, void *context) FOR_EACH_SENDER(i) { if (!senders[i]->post_select) continue; - senders[i]->post_select(&s->rfds, &s->wfds); + senders[i]->post_select(s); } if ((vss_playing() && !(mmd->vss_status_flags & VSS_PLAYING)) || (vss_next() && vss_playing())) -- 2.39.2