mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
Sync OpenBSD patchset 496:
Switch window pane pipe redirect fd over to a bufferevent.
This commit is contained in:
parent
971a7b2fe0
commit
cb0bf6a043
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-pipe-pane.c,v 1.4 2009-11-08 22:40:36 tcunha Exp $ */
|
/* $Id: cmd-pipe-pane.c,v 1.5 2009-11-08 22:59:53 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -31,6 +32,8 @@
|
|||||||
|
|
||||||
int cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
|
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 = {
|
const struct cmd_entry cmd_pipe_pane_entry = {
|
||||||
"pipe-pane", "pipep",
|
"pipe-pane", "pipep",
|
||||||
CMD_TARGET_PANE_USAGE "[-o] [command]",
|
CMD_TARGET_PANE_USAGE "[-o] [command]",
|
||||||
@ -55,7 +58,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
/* Destroy the old pipe. */
|
/* Destroy the old pipe. */
|
||||||
old_fd = wp->pipe_fd;
|
old_fd = wp->pipe_fd;
|
||||||
if (wp->pipe_fd != -1) {
|
if (wp->pipe_fd != -1) {
|
||||||
buffer_destroy(wp->pipe_buf);
|
bufferevent_free(wp->pipe_event);
|
||||||
close(wp->pipe_fd);
|
close(wp->pipe_fd);
|
||||||
wp->pipe_fd = -1;
|
wp->pipe_fd = -1;
|
||||||
}
|
}
|
||||||
@ -74,8 +77,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
/* Open the new pipe. */
|
/* Open the new pipe. */
|
||||||
if (pipe(pipe_fd) != 0) {
|
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||||
ctx->error(ctx, "pipe error: %s", strerror(errno));
|
ctx->error(ctx, "socketpair error: %s", strerror(errno));
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,9 +112,12 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
close(pipe_fd[1]);
|
close(pipe_fd[1]);
|
||||||
|
|
||||||
wp->pipe_fd = pipe_fd[0];
|
wp->pipe_fd = pipe_fd[0];
|
||||||
wp->pipe_buf = buffer_create(BUFSIZ);
|
|
||||||
wp->pipe_off = BUFFER_USED(wp->in);
|
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)
|
if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1)
|
||||||
fatal("fcntl failed");
|
fatal("fcntl failed");
|
||||||
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||||
@ -123,3 +129,14 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
|
|
||||||
return (0);
|
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;
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: server-window.c,v 1.7 2009-11-08 22:58:37 tcunha Exp $ */
|
/* $Id: server-window.c,v 1.8 2009-11-08 22:59:53 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -55,16 +55,6 @@ server_window_prepare(void)
|
|||||||
event_set(&wp->event,
|
event_set(&wp->event,
|
||||||
wp->fd, events, server_window_callback, wp);
|
wp->fd, events, server_window_callback, wp);
|
||||||
event_add(&wp->event, NULL);
|
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
|
} else
|
||||||
window_pane_parse(wp);
|
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. */
|
/* Window functions that need to happen every loop. */
|
||||||
|
5
tmux.h
5
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.499 2009-11-08 22:58:37 tcunha Exp $ */
|
/* $Id: tmux.h,v 1.500 2009-11-08 22:59:53 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -804,8 +804,7 @@ struct window_pane {
|
|||||||
struct input_ctx ictx;
|
struct input_ctx ictx;
|
||||||
|
|
||||||
int pipe_fd;
|
int pipe_fd;
|
||||||
struct event pipe_event;
|
struct bufferevent *pipe_event;
|
||||||
struct buffer *pipe_buf;
|
|
||||||
size_t pipe_off;
|
size_t pipe_off;
|
||||||
|
|
||||||
struct screen *screen;
|
struct screen *screen;
|
||||||
|
9
window.c
9
window.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: window.c,v 1.118 2009-11-08 22:40:36 tcunha Exp $ */
|
/* $Id: window.c,v 1.119 2009-11-08 22:59:53 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -424,8 +424,8 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
|
|||||||
wp->sy = sy;
|
wp->sy = sy;
|
||||||
|
|
||||||
wp->pipe_fd = -1;
|
wp->pipe_fd = -1;
|
||||||
wp->pipe_buf = NULL;
|
|
||||||
wp->pipe_off = 0;
|
wp->pipe_off = 0;
|
||||||
|
wp->pipe_event = NULL;
|
||||||
|
|
||||||
wp->saved_grid = NULL;
|
wp->saved_grid = NULL;
|
||||||
|
|
||||||
@ -451,9 +451,8 @@ window_pane_destroy(struct window_pane *wp)
|
|||||||
grid_destroy(wp->saved_grid);
|
grid_destroy(wp->saved_grid);
|
||||||
|
|
||||||
if (wp->pipe_fd != -1) {
|
if (wp->pipe_fd != -1) {
|
||||||
buffer_destroy(wp->pipe_buf);
|
|
||||||
close(wp->pipe_fd);
|
close(wp->pipe_fd);
|
||||||
event_del(&wp->pipe_event);
|
bufferevent_free(wp->pipe_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_destroy(wp->in);
|
buffer_destroy(wp->in);
|
||||||
@ -646,7 +645,7 @@ window_pane_parse(struct window_pane *wp)
|
|||||||
|
|
||||||
new_size = BUFFER_USED(wp->in) - wp->pipe_off;
|
new_size = BUFFER_USED(wp->in) - wp->pipe_off;
|
||||||
if (wp->pipe_fd != -1 && new_size > 0)
|
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);
|
input_parse(wp);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user