From 181beb316afad036ac01a778544c5dec0a8d51c7 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 30 Sep 2021 22:35:10 +0200 Subject: [PATCH] sched: Introduce sched_{read,write}_ok(). Two trivial wrappers for FD_ISSET() which hide the fact that we're still using the select(2) API. --- alsa_write.c | 2 +- audioc.c | 2 +- client_common.c | 8 ++++---- file_write.c | 2 +- http_recv.c | 2 +- oss_write.c | 2 +- play.c | 2 +- sched.h | 10 ++++++++++ stdout.c | 2 +- sync_filter.c | 2 +- vss.c | 8 ++++---- 11 files changed, 26 insertions(+), 16 deletions(-) diff --git a/alsa_write.c b/alsa_write.c index bbbf8b65..1e61a17f 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -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; diff --git a/audioc.c b/audioc.c index 76b3d6db..45688acb 100644 --- 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); diff --git a/client_common.c b/client_common.c index 499b6f95..7a353098 100644 --- a/client_common.c +++ b/client_common.c @@ -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) diff --git a/file_write.c b/file_write.c index 9a5ed5d7..d512df05 100644 --- a/file_write.c +++ b/file_write.c @@ -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); diff --git a/http_recv.c b/http_recv.c index 42098b7e..ac942b4f 100644 --- a/http_recv.c +++ b/http_recv.c @@ -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"); diff --git a/oss_write.c b/oss_write.c index 0565167c..75ad98b9 100644 --- a/oss_write.c +++ b/oss_write.c @@ -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 0c78b960..02fd27b3 100644 --- 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 4695da05..e0ca0c01 100644 --- 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); +} diff --git a/stdout.c b/stdout.c index 1f779109..71c45f69 100644 --- 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) { diff --git a/sync_filter.c b/sync_filter.c index 8e9ff2c5..3877c13d 100644 --- a/sync_filter.c +++ b/sync_filter.c @@ -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 f9bf57b5..23b64abb 100644 --- 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) -- 2.39.2