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);
}
/**
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)
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)
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)
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:
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:
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;
}
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)
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);
}
/**
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.
*
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);
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)
return;
if (ret < 0)
sched_min_delay(s);
- para_fd_set(gc->fd, &s->wfds, &s->max_fileno);
+ sched_monitor_writefd(gc->fd, s);
}
/*
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)
{
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);
}
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);
}
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);
}
/*
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);
}
}
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
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)
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)
{
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);
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);
+}
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)
{
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,
/**
* 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
_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);
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);
}
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);
}
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 */
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])
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;