aboutsummaryrefslogtreecommitdiff
path: root/server-job.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-10-22 19:41:51 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-10-22 19:41:51 +0000
commiteddcc3dfa9d3e5b45675de6287f0a359893b1bc1 (patch)
tree24b8c0bfbbac55730e8642a6b0046cf56e1fb86a /server-job.c
parentfd35b6f836565d2d46b8c9869f8ea6590face8d6 (diff)
downloadrtmux-eddcc3dfa9d3e5b45675de6287f0a359893b1bc1.tar.gz
rtmux-eddcc3dfa9d3e5b45675de6287f0a359893b1bc1.tar.bz2
rtmux-eddcc3dfa9d3e5b45675de6287f0a359893b1bc1.zip
Split the server code handling clients, jobs and windows off into separate
files from server.c (merging server-msg.c into the client file) and rather than iterating over each set after poll(), allow a callback to be specified when the fd is added and just walk once over the returned pollfds calling each callback where needed. More to come, getting this in so it is tested.
Diffstat (limited to 'server-job.c')
-rw-r--r--server-job.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/server-job.c b/server-job.c
new file mode 100644
index 00000000..f1903237
--- /dev/null
+++ b/server-job.c
@@ -0,0 +1,57 @@
+/* $OpenBSD$ */
+
+/*
+ * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <unistd.h>
+
+#include "tmux.h"
+
+/* Process a single job event. */
+void
+server_job_callback(int fd, int events, void *data)
+{
+ struct job *job = data;
+
+ if (job->fd == -1)
+ return;
+
+ if (buffer_poll(fd, events, job->out, NULL) != 0) {
+ close(job->fd);
+ job->fd = -1;
+ }
+}
+
+/* Job functions that happen once a loop. */
+void
+server_job_loop(void)
+{
+ struct job *job;
+
+restart:
+ SLIST_FOREACH(job, &all_jobs, lentry) {
+ if (job->flags & JOB_DONE || job->fd != -1 || job->pid != -1)
+ continue;
+ job->flags |= JOB_DONE;
+
+ if (job->callbackfn != NULL) {
+ job->callbackfn(job);
+ goto restart; /* could be freed by callback */
+ }
+ }
+}