summaryrefslogtreecommitdiffstats
path: root/buffer-poll.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-07-09 19:04:12 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-07-09 19:04:12 +0000
commita41ece5ff0d3ce7a0b7d987baa9759f8a012b48b (patch)
tree95adfffa5b036fe4c593254efd2b32aa03696b34 /buffer-poll.c
parent2905e0ef10926ab6f538598228a71e40844a8be6 (diff)
Initial import to CVS. Basic functions are working, albeit with a couple of showstopper memory bugs and many missing features. Detaching, reattaching, creating new sessions, listing sessions work acceptably for using with shells. Simple curses programs (top, systat, tetris) and more complicated ones (mutt, emacs) that don't require scrolling regions (ESC[r) mostly work fine (including mutt, emacs). No status bar yet and no key remapping or other customisation.
Diffstat (limited to 'buffer-poll.c')
-rw-r--r--buffer-poll.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/buffer-poll.c b/buffer-poll.c
new file mode 100644
index 00000000..e3c64832
--- /dev/null
+++ b/buffer-poll.c
@@ -0,0 +1,57 @@
+/* $Id: buffer-poll.c,v 1.1.1.1 2007-07-09 19:04:12 nicm Exp $ */
+
+/*
+ * Copyright (c) 2007 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 <errno.h>
+#include <poll.h>
+#include <unistd.h>
+
+#include "tmux.h"
+
+/* Fill buffers from socket based on poll results. */
+int
+buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out)
+{
+ ssize_t n;
+
+ if (pfd->revents & (POLLERR|POLLNVAL|POLLHUP))
+ return (-1);
+ if (pfd->revents & POLLIN) {
+ buffer_ensure(in, BUFSIZ);
+ n = read(pfd->fd, BUFFER_IN(in), BUFFER_FREE(in));
+ if (n == 0)
+ return (-1);
+ if (n == -1) {
+ if (errno != EINTR && errno != EAGAIN)
+ return (-1);
+ return (0);
+ }
+ buffer_add(in, n);
+ }
+ if (BUFFER_USED(out) > 0 && pfd->revents & POLLOUT) {
+ n = write(pfd->fd, BUFFER_OUT(out), BUFFER_USED(out));
+ if (n == -1) {
+ if (errno != EINTR && errno != EAGAIN)
+ return (-1);
+ return (0);
+ }
+ buffer_remove(out, n);
+ }
+ return (0);
+}