]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Hide implementation of para_fd_set().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 3 Oct 2021 19:52:02 +0000 (21:52 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 25 Aug 2022 13:37:26 +0000 (15:37 +0200)
This preparatory patch for replacing select() renames para_fd_set()
to sched_fd_set(), moves it to sched.c and makes it static. All
users are modified to call either of the two new public functions
sched_monitor_{read,write}fd() which take a pointer to struct sched
rather than an fd set pointer.

26 files changed:
afs.c
alsa_write.c
audioc.c
audiod.c
client_common.c
dccp_recv.c
dccp_send.c
fd.c
fd.h
file_write.c
grab_client.c
gui.c
http_recv.c
http_send.c
interactive.c
oss_write.c
play.c
sched.c
sched.h
server.c
signal.h
stdin.c
stdout.c
sync_filter.c
udp_recv.c
vss.c

diff --git a/afs.c b/afs.c
index 9f32c8aadb14a2125914ce24d945c9b8f9d8d377..99a53b68e11ec6fa1e11d7bfe6f0319c07993d25 100644 (file)
--- a/afs.c
+++ b/afs.c
@@ -767,10 +767,10 @@ static void command_pre_select(struct sched *s, void *context)
        struct command_task *ct = context;
        struct afs_client *client;
 
-       para_fd_set(server_socket, &s->rfds, &s->max_fileno);
-       para_fd_set(ct->fd, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(server_socket, s);
+       sched_monitor_readfd(ct->fd, s);
        list_for_each_entry(client, &afs_client_list, node)
-               para_fd_set(client->fd, &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(client->fd, s);
 }
 
 /**
index 1e61a17faf256df214b1f08f616fb2fcf24cd9dc..192233442b7346278634e749567d898dda5d05a8 100644 (file)
@@ -230,7 +230,7 @@ static void alsa_write_pre_select(struct sched *s, void *context)
                return;
        }
        pad->poll_fd = pfd.fd;
-       para_fd_set(pfd.fd, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(pfd.fd, s);
 }
 
 static void alsa_close(struct writer_node *wn)
index 45688acbdcb63cec5b97e9466da535c739b04909..248f6fb620291ff6ad05a21a8174a1635198b77c 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -150,7 +150,7 @@ static void audioc_pre_select(struct sched *s, void *context)
 
        if (ret < 0)
                sched_min_delay(s);
-       para_fd_set(at->fd, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(at->fd, s);
 }
 
 static int audioc_post_select(struct sched *s, void *context)
index 12de088639448ca9a227fa857bf99cb406e95b8b..1dc70e5e3fa0dc107920de755a1b6f99b35f31a1 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -1078,7 +1078,7 @@ static int signal_post_select(struct sched *s, void *context)
 static void command_pre_select(struct sched *s, void *context)
 {
        struct command_task *ct = context;
-       para_fd_set(ct->fd, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(ct->fd, s);
 }
 
 static int command_post_select(struct sched *s, void *context)
index 7a353098c42ecfab3f36452b9e82d4a4a8637c32..fdd04e5acf450073a0ee73683e9818d0a42f38e4 100644 (file)
@@ -68,13 +68,13 @@ static void client_pre_select(struct sched *s, void *context)
        case CL_CONNECTED:
        case CL_SENT_AUTH:
        case CL_SENT_CH_RESPONSE:
-               para_fd_set(ct->scc.fd, &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(ct->scc.fd, s);
                return;
 
        case CL_RECEIVED_WELCOME:
        case CL_RECEIVED_PROCEED:
        case CL_RECEIVED_CHALLENGE:
-               para_fd_set(ct->scc.fd, &s->wfds, &s->max_fileno);
+               sched_monitor_writefd(ct->scc.fd, s);
                return;
 
        case CL_SENDING:
@@ -83,7 +83,7 @@ static void client_pre_select(struct sched *s, void *context)
                        if (ret < 0)
                                sched_min_delay(s);
                        else if (ret > 0)
-                               para_fd_set(ct->scc.fd, &s->wfds, &s->max_fileno);
+                               sched_monitor_writefd(ct->scc.fd, s);
                }
                __attribute__ ((fallthrough));
        case CL_EXECUTING:
@@ -92,7 +92,7 @@ static void client_pre_select(struct sched *s, void *context)
                        if (ret < 0)
                                sched_min_delay(s);
                        else if (ret > 0)
-                               para_fd_set(ct->scc.fd, &s->rfds, &s->max_fileno);
+                               sched_monitor_readfd(ct->scc.fd, s);
                }
                return;
        }
index 1773ffe7429e087236c08a938f142559faae24d2..9a17269d7084f89c064d764571e1a78ba9452e7d 100644 (file)
@@ -115,7 +115,7 @@ static void dccp_recv_pre_select(struct sched *s, void *context)
 
        if (generic_recv_pre_select(s, rn) <= 0)
                return;
-       para_fd_set(rn->fd, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(rn->fd, s);
 }
 
 static int dccp_recv_post_select(__a_unused struct sched *s, void *context)
index 47d6b4089d8f7f229c27d3af262068f2d37ee2c3..5c274237ce33a106c90b3570b000f01572c5ad44 100644 (file)
@@ -42,7 +42,7 @@ static void dccp_pre_select(struct sched *s)
 
        FOR_EACH_LISTEN_FD(n, dss)
                if (dss->listen_fds[n] >= 0)
-                       para_fd_set(dss->listen_fds[n], &s->rfds, &s->max_fileno);
+                       sched_monitor_readfd(dss->listen_fds[n], s);
 }
 
 /**
diff --git a/fd.c b/fd.c
index f7e0e42b3680707774cddd5c3bbd0c56cfc54bcb..b8d1062d1ce98628468dfd7b184f4db346ef60ee 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -376,34 +376,6 @@ __must_check int mark_fd_nonblocking(int fd)
        return 1;
 }
 
-/**
- * Set a file descriptor in a fd_set.
- *
- * \param fd The file descriptor to be set.
- * \param fds The file descriptor set.
- * \param max_fileno Highest-numbered file descriptor.
- *
- * This wrapper for FD_SET() passes its first two arguments to \p FD_SET. Upon
- * return, \a max_fileno contains the maximum of the old_value and \a fd.
- *
- * \sa \ref para_select.
-*/
-void para_fd_set(int fd, fd_set *fds, int *max_fileno)
-{
-       assert(fd >= 0 && fd < FD_SETSIZE);
-#if 0
-       {
-               int flags = fcntl(fd, F_GETFL);
-               if (!(flags & O_NONBLOCK)) {
-                       PARA_EMERG_LOG("fd %d is a blocking file descriptor\n", fd);
-                       exit(EXIT_FAILURE);
-               }
-       }
-#endif
-       FD_SET(fd, fds);
-       *max_fileno = PARA_MAX(*max_fileno, fd);
-}
-
 /**
  * Paraslash's wrapper for mmap.
  *
diff --git a/fd.h b/fd.h
index 37d3ace91b42ba9f7c0c47732e5762e58c8523ad..ea6307b2d5145d3ce38b0372f2e308a468d94ab4 100644 (file)
--- a/fd.h
+++ b/fd.h
@@ -9,7 +9,6 @@ bool file_exists(const char *);
 int para_select(int n, fd_set *readfds, fd_set *writefds, int timeout);
 __must_check int mark_fd_nonblocking(int fd);
 __must_check int mark_fd_blocking(int fd);
-void para_fd_set(int fd, fd_set *fds, int *max_fileno);
 int para_mmap(size_t length, int prot, int flags, int fd, void *map);
 int para_open(const char *path, int flags, mode_t mode);
 int para_mkdir(const char *path, mode_t mode);
index d512df0598eab8d105c1145852c6738e27bd1752..86c4e8ea02c9e91c9629e2391998a4c271ecfb26 100644 (file)
@@ -79,7 +79,7 @@ static void file_write_pre_select(struct sched *s, void *context)
                return;
        if (ret < 0 || !pfwd)
                return sched_min_delay(s);
-       para_fd_set(pfwd->fd, &s->wfds, &s->max_fileno);
+       sched_monitor_writefd(pfwd->fd, s);
 }
 
 static void file_write_close(struct writer_node *wn)
index 8370649301906eaef68a4c30d1b1f3975283dea8..04d90169864e50dd9b018159ac079551f39fd4ef 100644 (file)
@@ -98,7 +98,7 @@ static void gc_pre_select(struct sched *s, void *context)
                return;
        if (ret < 0)
                sched_min_delay(s);
-       para_fd_set(gc->fd, &s->wfds, &s->max_fileno);
+       sched_monitor_writefd(gc->fd, s);
 }
 
 /*
diff --git a/gui.c b/gui.c
index 686fda3108e6d604b905d06176df3801d239807d..fc7bfaf4e5d362f2323b4b760777b4219f0dfab0 100644 (file)
--- a/gui.c
+++ b/gui.c
@@ -614,7 +614,7 @@ static void status_pre_select(struct sched *s, void *context)
        struct status_task *st = context;
 
        if (st->fd >= 0)
-               para_fd_set(st->fd, &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(st->fd, s);
        if (task_get_notification(st->task) < 0)
                return sched_min_delay(s);
        if (st->fd < 0)
@@ -935,9 +935,9 @@ static void exec_pre_select(struct sched *s, void *context)
 {
        struct exec_task *et = context;
        if (exec_fds[0] >= 0)
-               para_fd_set(exec_fds[0], &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(exec_fds[0], s);
        if (exec_fds[1] >= 0)
-               para_fd_set(exec_fds[1], &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(exec_fds[1], s);
        if (task_get_notification(et->task) < 0)
                sched_min_delay(s);
 }
@@ -995,7 +995,7 @@ static int exec_post_select(__a_unused struct sched *s, void *context)
 static void input_pre_select(struct sched *s, __a_unused void *context)
 {
        if (exec_status() != EXEC_XCMD)
-               para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(STDIN_FILENO, s);
        if (window_update_needed())
                sched_min_delay(s);
 }
index ac942b4f26e5012b3d92ecf655b6311ad2d9c489..94e24d1b34c8c14170826ede5c1982456f6d1b3a 100644 (file)
@@ -64,9 +64,9 @@ static void http_recv_pre_select(struct sched *s, void *context)
        if (generic_recv_pre_select(s, rn) <= 0)
                return;
        if  (phd->status == HTTP_CONNECTED)
-               para_fd_set(rn->fd, &s->wfds, &s->max_fileno);
+               sched_monitor_writefd(rn->fd, s);
        else
-               para_fd_set(rn->fd, &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(rn->fd, s);
 }
 
 /*
index 6d026c715a09cf4a3599687cf7a5c5a2282c4a65..59fe2efa0419b0376201b236431fd2ea605273e2 100644 (file)
@@ -204,15 +204,15 @@ static void http_pre_select(struct sched *s)
        FOR_EACH_LISTEN_FD(n, hss) {
                if (hss->listen_fds[n] < 0)
                        continue;
-               para_fd_set(hss->listen_fds[n], &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(hss->listen_fds[n], s);
        }
        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, &s->rfds, &s->max_fileno);
+                       sched_monitor_readfd(sc->fd, s);
                if (phsd->status == HTTP_GOT_GET_REQUEST ||
                                phsd->status == HTTP_INVALID_GET_REQUEST)
-                       para_fd_set(sc->fd, &s->wfds, &s->max_fileno);
+                       sched_monitor_writefd(sc->fd, s);
        }
 }
 
index 3af90a6814d79e248178a3e47ae04cd066a8efad..729a0dd5bd4b5d68423d044411ba27b7a9bcc992 100644 (file)
@@ -377,7 +377,7 @@ static void i9e_pre_select(struct sched *s, __a_unused void *context)
                        return;
                }
                if (ret > 0)
-                       para_fd_set(i9ep->ici->fds[1], &s->wfds, &s->max_fileno);
+                       sched_monitor_writefd(i9ep->ici->fds[1], s);
        }
        /*
         * fd[0] might have been reset to blocking mode if our job was moved to
@@ -388,7 +388,7 @@ static void i9e_pre_select(struct sched *s, __a_unused void *context)
        if (ret < 0)
                PARA_WARNING_LOG("set to nonblock failed: (fd0 %d, %s)\n",
                        i9ep->ici->fds[0], para_strerror(-ret));
-       para_fd_set(i9ep->ici->fds[0], &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(i9ep->ici->fds[0], s);
 }
 
 static void update_winsize(void)
index 75ad98b9faac0acfa912628c6bafed31d085b90b..794f4242368b623a27f84d822e6c4960951cd919 100644 (file)
@@ -71,7 +71,7 @@ static void oss_pre_select(struct sched *s, void *context)
                return;
        if (ret < 0 || !powd)
                return sched_min_delay(s);
-       para_fd_set(powd->fd, &s->wfds, &s->max_fileno);
+       sched_monitor_writefd(powd->fd, s);
 }
 
 static void oss_close(struct writer_node *wn)
diff --git a/play.c b/play.c
index 02fd27b3ac381562e2656cb3dc6144d8425cb6f3..feb0f9976547a342e032120d901f1563afc86079 100644 (file)
--- a/play.c
+++ b/play.c
@@ -1168,7 +1168,7 @@ static void play_pre_select(struct sched *s, __a_unused void *context)
 {
        char state;
 
-       para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(STDIN_FILENO, s);
        state = get_playback_state();
        if (state == 'R' || state == 'F' || state == 'X')
                return sched_min_delay(s);
diff --git a/sched.c b/sched.c
index 8deb7f383596162e97444c7766f6d15bc60eb92c..4ca040f44f337a126ab24b4ec36fb297fa273687 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -451,3 +451,45 @@ int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s)
        sched_request_timeout(&diff, s);
        return 1;
 }
+
+static void sched_fd_set(int fd, fd_set *fds, int *max_fileno)
+{
+       assert(fd >= 0 && fd < FD_SETSIZE);
+#if 0
+       {
+               int flags = fcntl(fd, F_GETFL);
+               if (!(flags & O_NONBLOCK)) {
+                       PARA_EMERG_LOG("fd %d is a blocking file descriptor\n", fd);
+                       exit(EXIT_FAILURE);
+               }
+       }
+#endif
+       FD_SET(fd, fds);
+       *max_fileno = PARA_MAX(*max_fileno, fd);
+}
+
+/**
+ * Instruct the scheduler to monitor an fd for readiness for reading.
+ *
+ * \param fd The file descriptor.
+ * \param s The scheduler.
+ *
+ * \sa \ref sched_monitor_writefd().
+ */
+void sched_monitor_readfd(int fd, struct sched *s)
+{
+       sched_fd_set(fd, &s->rfds, &s->max_fileno);
+}
+
+/**
+ * Instruct the scheduler to monitor an fd for readiness for writing.
+ *
+ * \param fd The file descriptor.
+ * \param s The scheduler.
+ *
+ * \sa \ref sched_monitor_readfd().
+ */
+void sched_monitor_writefd(int fd, struct sched *s)
+{
+       sched_fd_set(fd, &s->wfds, &s->max_fileno);
+}
diff --git a/sched.h b/sched.h
index e0ca0c011bb0d4838a4071098e4c172403fac015..d9e852447ec55c27e4fc77a86185fcaa4a68bd06 100644 (file)
--- a/sched.h
+++ b/sched.h
@@ -80,6 +80,8 @@ void sched_request_timeout(struct timeval *to, struct sched *s);
 void sched_request_timeout_ms(long unsigned ms, struct sched *s);
 int sched_request_barrier(struct timeval *barrier, struct sched *s);
 int sched_request_barrier_or_min_delay(struct timeval *barrier, struct sched *s);
+void sched_monitor_readfd(int fd, struct sched *s);
+void sched_monitor_writefd(int fd, struct sched *s);
 
 static inline bool sched_read_ok(int fd, const struct sched *s)
 {
index ca00d0e9eb7c2635ae4aa534108e7e3f4a808cdc..91fb9dff47dbefa6ca0207852a861bbb8d7f1a5e 100644 (file)
--- a/server.c
+++ b/server.c
@@ -326,7 +326,7 @@ static void command_pre_select(struct sched *s, void *context)
        struct server_command_task *sct = context;
 
        for (n = 0; n < sct->num_listen_fds; n++)
-               para_fd_set(sct->listen_fds[n], &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(sct->listen_fds[n], s);
 }
 
 static int command_task_accept(unsigned listen_idx, struct sched *s,
index 2f3422e2f6e3912350cb92583d5ad01f01e08392..3522102421cd5fdcd9a2f5ca0b5fef4f63330859 100644 (file)
--- a/signal.h
+++ b/signal.h
@@ -15,7 +15,7 @@ struct signal_task {
 /**
  * A generic pre-select method for signal tasks.
  *
- * \param s Passed to para_fd_set().
+ * \param s Used to watch the signal fd for reading.
  * \param context Signal task pointer.
  *
  * This convenience helper is called from several programs which need to handle
@@ -31,7 +31,7 @@ struct signal_task {
 _static_inline_ void signal_pre_select(struct sched *s, void *context)
 {
        struct signal_task *st = context;
-       para_fd_set(st->fd, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(st->fd, s);
 }
 
 struct signal_task *signal_init_or_die(void);
diff --git a/stdin.c b/stdin.c
index eea78b3eb8cabee7c39900c248a2e9f116426872..5f9259f7171c50dbdb1e164f6bc36257f45cc253 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -28,7 +28,7 @@ static void stdin_pre_select(struct sched *s, void *context)
        if (ret <= 0)
                return;
        if (btr_pool_unused(sit->btrp) > 0)
-               return para_fd_set(STDIN_FILENO, &s->rfds, &s->max_fileno);
+               return sched_monitor_readfd(STDIN_FILENO, s);
        sched_request_timeout_ms(100, s);
 }
 
index 71c45f69518b349d07143823003dedac9a0f5e2f..4af40984b909121460344a53a855a5753c10c4d0 100644 (file)
--- a/stdout.c
+++ b/stdout.c
@@ -18,7 +18,7 @@ static void stdout_pre_select(struct sched *s, void *context)
 
        ret = btr_node_status(sot->btrn, 0, BTR_NT_LEAF);
        if (ret > 0)
-               para_fd_set(STDOUT_FILENO, &s->wfds, &s->max_fileno);
+               sched_monitor_writefd(STDOUT_FILENO, s);
        else if (ret < 0)
                sched_min_delay(s);
 }
index 3877c13d1d932bc566303299565d87d3e6c948e6..ec5bb2736a041748c6fb5d7371e731b86147e784 100644 (file)
@@ -261,7 +261,7 @@ static void sync_pre_select(struct sched *s, void *context)
        ret = btr_node_status(fn->btrn, 0, BTR_NT_INTERNAL);
        if (ret < 0)
                return sched_min_delay(s);
-       para_fd_set(ctx->listen_fd, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(ctx->listen_fd, s);
        if (ret == 0)
                return;
        if (ctx->timeout.tv_sec == 0) { /* must ping buddies */
index cc6e2049968cec0628d42cdc41066ee34294e49d..94ad45125c7ccca7fd0dc0e2f5ea420adad080ec 100644 (file)
@@ -29,7 +29,7 @@ static void udp_recv_pre_select(struct sched *s, void *context)
 
        if (generic_recv_pre_select(s, rn) <= 0)
                return;
-       para_fd_set(rn->fd, &s->rfds, &s->max_fileno);
+       sched_monitor_readfd(rn->fd, s);
 }
 
 static int udp_check_eof(size_t sz, struct iovec iov[2])
diff --git a/vss.c b/vss.c
index d2fbfb3424162afdab808d52bf40c33c83e61295..fce5281b5d3f750592016839bd14649452a93011 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -899,10 +899,10 @@ static void vss_pre_select(struct sched *s, void *context)
 
        if (need_to_request_new_audio_file(vsst)) {
                PARA_DEBUG_LOG("ready and playing, but no audio file\n");
-               para_fd_set(vsst->afs_socket, &s->wfds, &s->max_fileno);
+               sched_monitor_writefd(vsst->afs_socket, s);
                vsst->afsss = AFS_SOCKET_CHECK_FOR_WRITE;
        } else
-               para_fd_set(vsst->afs_socket, &s->rfds, &s->max_fileno);
+               sched_monitor_readfd(vsst->afs_socket, s);
        FOR_EACH_SENDER(i) {
                if (!senders[i]->pre_select)
                        continue;