]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
sched: Introduce sched_{read,write}_ok().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 30 Sep 2021 20:35:10 +0000 (22:35 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 25 Aug 2022 13:37:26 +0000 (15:37 +0200)
Two trivial wrappers for FD_ISSET() which hide the fact that we're
still using the select(2) API.

alsa_write.c
audioc.c
client_common.c
file_write.c
http_recv.c
oss_write.c
play.c
sched.h
stdout.c
sync_filter.c
vss.c

index bbbf8b650ac86c4952ac46f22c166583018bfb88..1e61a17faf256df214b1f08f616fb2fcf24cd9dc 100644 (file)
@@ -321,7 +321,7 @@ again:
        frames = snd_pcm_writei(pad->handle, data, frames);
        if (frames == 0 || frames == -EAGAIN) {
                char buf[100];
-               if (pad->poll_fd >= 0 && FD_ISSET(pad->poll_fd, &s->rfds))
+               if (pad->poll_fd >= 0 && sched_read_ok(pad->poll_fd, s))
                        if (read(pad->poll_fd, buf, 100))
                                do_nothing;
                return 0;
index 76b3d6dba0b3c67742e78903e6352949da4285c4..45688acbdcb63cec5b97e9466da535c739b04909 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -162,7 +162,7 @@ static int audioc_post_select(struct sched *s, void *context)
 
        if (ret < 0)
                goto out;
-       if (!FD_ISSET(at->fd, &s->rfds))
+       if (!sched_read_ok(at->fd, s))
                return 0;
        bufsize = PARA_MAX(1024U, OPT_UINT32_VAL(BUFSIZE));
        buf = para_malloc(bufsize);
index 499b6f9595c51f726cb875b54b024467b3aa98ec..7a353098c42ecfab3f36452b9e82d4a4a8637c32 100644 (file)
@@ -299,7 +299,7 @@ static int client_post_select(struct sched *s, void *context)
                 * 0.8.0 we no longer need to request the feature.
                 */
                bool has_sha256;
-               if (!FD_ISSET(ct->scc.fd, &s->wfds))
+               if (!sched_write_ok(ct->scc.fd, s))
                        return 0;
                has_sha256 = has_feature("sha256", ct);
                sprintf(buf, AUTH_REQUEST_MSG "%s%s", ct->user, has_sha256?
@@ -380,7 +380,7 @@ static int client_post_select(struct sched *s, void *context)
                }
        case CL_RECEIVED_PROCEED: /* concat args and send command */
                {
-               if (!FD_ISSET(ct->scc.fd, &s->wfds))
+               if (!sched_write_ok(ct->scc.fd, s))
                        return 0;
                ret = send_sb_command(ct);
                if (ret <= 0)
@@ -402,7 +402,7 @@ static int client_post_select(struct sched *s, void *context)
                        }
                        if (ret < 0)
                                goto close1;
-                       if (ret > 0 && FD_ISSET(ct->scc.fd, &s->wfds)) {
+                       if (ret > 0 && sched_write_ok(ct->scc.fd, s)) {
                                sz = btr_next_buffer(ct->btrn[1], &buf2);
                                assert(sz);
                                ret = send_sb(ct, 1, buf2, sz, SBD_BLOB_DATA, true);
@@ -418,7 +418,7 @@ static int client_post_select(struct sched *s, void *context)
                        ret = btr_node_status(ct->btrn[0], 0, BTR_NT_ROOT);
                        if (ret < 0)
                                goto close0;
-                       if (ret > 0 && FD_ISSET(ct->scc.fd, &s->rfds)) {
+                       if (ret > 0 && sched_read_ok(ct->scc.fd, s)) {
                                struct sb_buffer sbb;
                                ret = recv_sb(ct, &sbb);
                                if (ret < 0)
index 9a5ed5d7fab7dc01fe46fa5ecab6940ea3a28828..d512df0598eab8d105c1145852c6738e27bd1752 100644 (file)
@@ -111,7 +111,7 @@ static int file_write_post_select(__a_unused struct sched *s, void *context)
                ret = prepare_output_file(wn);
                goto out;
        }
-       if (!FD_ISSET(pfwd->fd, &s->wfds))
+       if (!sched_write_ok(pfwd->fd, s))
                return 0;
        bytes = btr_next_buffer(btrn, &buf);
        assert(bytes > 0);
index 42098b7e9ee622f1e3b4cb0b5b16b29a51805da2..ac942b4f26e5012b3d92ecf655b6311ad2d9c489 100644 (file)
@@ -93,7 +93,7 @@ static int http_recv_post_select(struct sched *s, void *context)
                return 0;
        if (phd->status == HTTP_CONNECTED) {
                char *rq;
-               if (!FD_ISSET(rn->fd, &s->wfds))
+               if (!sched_write_ok(rn->fd, s))
                        return 0;
                rq = make_request_msg();
                PARA_INFO_LOG("sending http request\n");
index 0565167c256a43bfe86a6442f195a320e1458db8..75ad98b9faac0acfa912628c6bafed31d085b90b 100644 (file)
@@ -222,7 +222,7 @@ static int oss_post_select(__a_unused struct sched *s, void *context)
                goto out;
        }
        ret = 0;
-       if (!FD_ISSET(powd->fd, &s->wfds))
+       if (!sched_write_ok(powd->fd, s))
                goto out;
        /* get maximal number of bytes that can be written */
        ret = ioctl(powd->fd, SNDCTL_DSP_GETOSPACE, &abi);
diff --git a/play.c b/play.c
index 0c78b960f1161f9ecad7c1a4f1f06c3e75e9974f..02fd27b3ac381562e2656cb3dc6144d8425cb6f3 100644 (file)
--- a/play.c
+++ b/play.c
@@ -1145,7 +1145,7 @@ static int session_post_select(struct sched *s)
 {
        char c;
 
-       if (!FD_ISSET(STDIN_FILENO, &s->rfds))
+       if (!sched_read_ok(STDIN_FILENO, s))
                return 0;
        if (read(STDIN_FILENO, &c, 1))
                do_nothing;
diff --git a/sched.h b/sched.h
index 4695da05040d1934e0c23a12db9bb14c7e9f799c..e0ca0c011bb0d4838a4071098e4c172403fac015 100644 (file)
--- a/sched.h
+++ b/sched.h
@@ -80,3 +80,13 @@ 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);
+
+static inline bool sched_read_ok(int fd, const struct sched *s)
+{
+       return FD_ISSET(fd, &s->rfds);
+}
+
+static inline bool sched_write_ok(int fd, const struct sched *s)
+{
+       return FD_ISSET(fd, &s->wfds);
+}
index 1f7791094a33a961c193c273a4c09e9b16f2be07..71c45f69518b349d07143823003dedac9a0f5e2f 100644 (file)
--- a/stdout.c
+++ b/stdout.c
@@ -40,7 +40,7 @@ static int stdout_post_select(struct sched *s, void *context)
                goto out;
        if (ret == 0)
                return 0;
-       if (!FD_ISSET(STDOUT_FILENO, &s->wfds))
+       if (!sched_write_ok(STDOUT_FILENO, s))
                return 0;
 
        if (sot->must_set_nonblock_flag) {
index 8e9ff2c5de79a6385b6472453f3dec417b9ac5cc..3877c13d1d932bc566303299565d87d3e6c948e6 100644 (file)
@@ -324,7 +324,7 @@ static int sync_post_select(__a_unused struct sched *s, void *context)
                }
                ctx->ping_sent = true;
        }
-       if (FD_ISSET(ctx->listen_fd, &s->rfds)) {
+       if (sched_read_ok(ctx->listen_fd, s)) {
                char c;
                for (;;) {
                        struct sockaddr src_addr;
diff --git a/vss.c b/vss.c
index f9bf57b5575a7348fa5b5bb8a2db3c446d9dd92c..23b64abbc2429d9b8a9baaa45e0ee16d881800e2 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -950,13 +950,13 @@ static int recv_afs_msg(int afs_socket, int *fd, uint32_t *code, uint32_t *data)
 #define MAP_POPULATE 0
 #endif
 
-static void recv_afs_result(struct vss_task *vsst, fd_set *rfds)
+static void recv_afs_result(struct vss_task *vsst, const struct sched *s)
 {
        int ret, passed_fd, shmid;
        uint32_t afs_code = 0, afs_data = 0;
        struct stat statbuf;
 
-       if (!FD_ISSET(vsst->afs_socket, rfds))
+       if (!sched_read_ok(vsst->afs_socket, s))
                return;
        ret = recv_afs_msg(vsst->afs_socket, &passed_fd, &afs_code, &afs_data);
        if (ret == -ERRNO_TO_PARA_ERROR(EAGAIN))
@@ -1137,8 +1137,8 @@ static int vss_post_select(struct sched *s, void *context)
                mmd->sender_cmd_data.cmd_num = -1;
        }
        if (vsst->afsss != AFS_SOCKET_CHECK_FOR_WRITE)
-               recv_afs_result(vsst, &s->rfds);
-       else if (FD_ISSET(vsst->afs_socket, &s->wfds)) {
+               recv_afs_result(vsst, s);
+       else if (sched_write_ok(vsst->afs_socket, s)) {
                PARA_INFO_LOG("requesting new fd from afs\n");
                ret = write_buffer(vsst->afs_socket, "new");
                if (ret < 0)