]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - sched.c
Hide implementation of para_fd_set().
[paraslash.git] / sched.c
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);
+}