summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-11-04 22:02:39 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-11-04 22:02:39 +0000
commit4d0bbc1e01f1fde69f49b0be9924ff8916650505 (patch)
treeb02f1fd2c832c76847d276485b7aa1fdda4f10f5 /usr.bin
parent61f1e016a392ec594bd75c723836afda9e8af879 (diff)
Switch window pane pipe redirect fd over to a bufferevent.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-pipe-pane.c27
-rw-r--r--usr.bin/tmux/server-window.c20
-rw-r--r--usr.bin/tmux/tmux.h5
-rw-r--r--usr.bin/tmux/window.c9
4 files changed, 29 insertions, 32 deletions
diff --git a/usr.bin/tmux/cmd-pipe-pane.c b/usr.bin/tmux/cmd-pipe-pane.c
index e3e4dd56cfc..bcd835657ed 100644
--- a/usr.bin/tmux/cmd-pipe-pane.c
+++ b/usr.bin/tmux/cmd-pipe-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-pipe-pane.c,v 1.3 2009/11/04 20:50:11 nicm Exp $ */
+/* $OpenBSD: cmd-pipe-pane.c,v 1.4 2009/11/04 22:02:38 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -17,6 +17,7 @@
*/
#include <sys/types.h>
+#include <sys/socket.h>
#include <errno.h>
#include <fcntl.h>
@@ -32,6 +33,8 @@
int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
+void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
+
const struct cmd_entry cmd_pipe_pane_entry = {
"pipe-pane", "pipep",
CMD_TARGET_PANE_USAGE "[-o] [command]",
@@ -56,7 +59,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Destroy the old pipe. */
old_fd = wp->pipe_fd;
if (wp->pipe_fd != -1) {
- buffer_destroy(wp->pipe_buf);
+ bufferevent_free(wp->pipe_event);
close(wp->pipe_fd);
wp->pipe_fd = -1;
}
@@ -75,8 +78,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
return (0);
/* Open the new pipe. */
- if (pipe(pipe_fd) != 0) {
- ctx->error(ctx, "pipe error: %s", strerror(errno));
+ if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
+ ctx->error(ctx, "socketpair error: %s", strerror(errno));
return (-1);
}
@@ -110,9 +113,12 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
close(pipe_fd[1]);
wp->pipe_fd = pipe_fd[0];
- wp->pipe_buf = buffer_create(BUFSIZ);
wp->pipe_off = BUFFER_USED(wp->in);
+ wp->pipe_event = bufferevent_new(wp->pipe_fd,
+ NULL, NULL, cmd_pipe_pane_error_callback, wp);
+ bufferevent_enable(wp->pipe_event, EV_WRITE);
+
if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1)
fatal("fcntl failed");
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
@@ -124,3 +130,14 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
return (0);
}
+
+void
+cmd_pipe_pane_error_callback(
+ unused struct bufferevent *bufev, unused short what, void *data)
+{
+ struct window_pane *wp = data;
+
+ bufferevent_free(wp->pipe_event);
+ close(wp->pipe_fd);
+ wp->pipe_fd = -1;
+}
diff --git a/usr.bin/tmux/server-window.c b/usr.bin/tmux/server-window.c
index aef03280a16..868437650eb 100644
--- a/usr.bin/tmux/server-window.c
+++ b/usr.bin/tmux/server-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-window.c,v 1.7 2009/11/04 21:47:42 nicm Exp $ */
+/* $OpenBSD: server-window.c,v 1.8 2009/11/04 22:02:38 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -55,16 +55,6 @@ server_window_prepare(void)
event_set(&wp->event,
wp->fd, events, server_window_callback, wp);
event_add(&wp->event, NULL);
-
- if (wp->pipe_fd == -1)
- continue;
- events = 0;
- if (BUFFER_USED(wp->pipe_buf) > 0)
- events |= EV_WRITE;
- event_del(&wp->pipe_event);
- event_set(&wp->pipe_event,
- wp->pipe_fd, events, server_window_callback, wp);
- event_add(&wp->pipe_event, NULL);
}
}
}
@@ -110,14 +100,6 @@ server_window_callback(int fd, short events, void *data)
} else
window_pane_parse(wp);
}
-
- if (fd == wp->pipe_fd) {
- if (buffer_poll(fd, events, NULL, wp->pipe_buf) != 0) {
- buffer_destroy(wp->pipe_buf);
- close(wp->pipe_fd);
- wp->pipe_fd = -1;
- }
- }
}
/* Window functions that need to happen every loop. */
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 9ed46d25707..9761eeab479 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.161 2009/11/04 21:47:42 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.162 2009/11/04 22:02:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -805,8 +805,7 @@ struct window_pane {
struct input_ctx ictx;
int pipe_fd;
- struct event pipe_event;
- struct buffer *pipe_buf;
+ struct bufferevent *pipe_event;
size_t pipe_off;
struct screen *screen;
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 90fec083417..2417f06dcc5 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.35 2009/11/04 20:50:11 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.36 2009/11/04 22:02:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -426,8 +426,8 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->sy = sy;
wp->pipe_fd = -1;
- wp->pipe_buf = NULL;
wp->pipe_off = 0;
+ wp->pipe_event = NULL;
wp->saved_grid = NULL;
@@ -453,9 +453,8 @@ window_pane_destroy(struct window_pane *wp)
grid_destroy(wp->saved_grid);
if (wp->pipe_fd != -1) {
- buffer_destroy(wp->pipe_buf);
close(wp->pipe_fd);
- event_del(&wp->pipe_event);
+ bufferevent_free(wp->pipe_event);
}
buffer_destroy(wp->in);
@@ -639,7 +638,7 @@ window_pane_parse(struct window_pane *wp)
new_size = BUFFER_USED(wp->in) - wp->pipe_off;
if (wp->pipe_fd != -1 && new_size > 0)
- buffer_write(wp->pipe_buf, BUFFER_OUT(wp->in), new_size);
+ bufferevent_write(wp->pipe_event, BUFFER_OUT(wp->in), new_size);
input_parse(wp);