mirror of
https://github.com/tmux/tmux.git
synced 2024-11-05 02:18:47 +00:00
Sync OpenBSD patchset 495:
Switch tty fds over to a bufferevent.
This commit is contained in:
parent
7851bb81f5
commit
971a7b2fe0
@ -1,4 +1,4 @@
|
||||
/* $Id: server-client.c,v 1.13 2009-11-08 22:40:36 tcunha Exp $ */
|
||||
/* $Id: server-client.c,v 1.14 2009-11-08 22:58:37 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -135,8 +135,7 @@ server_client_lost(struct client *c)
|
||||
close(c->ibuf.fd);
|
||||
imsg_clear(&c->ibuf);
|
||||
event_del(&c->event);
|
||||
event_del(&c->tty.event);
|
||||
|
||||
|
||||
for (i = 0; i < ARRAY_LENGTH(&dead_clients); i++) {
|
||||
if (ARRAY_ITEM(&dead_clients, i) == NULL) {
|
||||
ARRAY_SET(&dead_clients, i, c);
|
||||
@ -171,18 +170,6 @@ server_client_prepare(void)
|
||||
event_set(&c->event,
|
||||
c->ibuf.fd, events, server_client_callback, c);
|
||||
event_add(&c->event, NULL);
|
||||
|
||||
if (c->tty.fd == -1)
|
||||
continue;
|
||||
if (c->flags & CLIENT_SUSPENDED || c->session == NULL)
|
||||
continue;
|
||||
events = EV_READ;
|
||||
if (BUFFER_USED(c->tty.out) > 0)
|
||||
events |= EV_WRITE;
|
||||
event_del(&c->tty.event);
|
||||
event_set(&c->tty.event,
|
||||
c->tty.fd, events, server_client_callback, c);
|
||||
event_add(&c->tty.event, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,14 +195,6 @@ server_client_callback(int fd, short events, void *data)
|
||||
if (events & EV_READ && server_client_msg_dispatch(c) != 0)
|
||||
goto client_lost;
|
||||
}
|
||||
|
||||
if (c->tty.fd != -1 && fd == c->tty.fd) {
|
||||
if (c->flags & CLIENT_SUSPENDED || c->session == NULL)
|
||||
return;
|
||||
|
||||
if (buffer_poll(fd, events, c->tty.in, c->tty.out) != 0)
|
||||
goto client_lost;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: server-window.c,v 1.6 2009-11-08 22:53:13 tcunha Exp $ */
|
||||
/* $Id: server-window.c,v 1.7 2009-11-08 22:58:37 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -87,7 +87,8 @@ server_window_backoff(struct window_pane *wp)
|
||||
continue;
|
||||
if (c->session->curw->window != wp->window)
|
||||
continue;
|
||||
if (BUFFER_USED(c->tty.out) > BACKOFF_THRESHOLD)
|
||||
|
||||
if (EVBUFFER_LENGTH(c->tty.event->output) > BACKOFF_THRESHOLD)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
|
6
tmux.h
6
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.498 2009-11-08 22:56:04 tcunha Exp $ */
|
||||
/* $Id: tmux.h,v 1.499 2009-11-08 22:58:37 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -999,9 +999,7 @@ struct tty {
|
||||
struct tty_term *term;
|
||||
|
||||
int fd;
|
||||
struct event event;
|
||||
struct buffer *in;
|
||||
struct buffer *out;
|
||||
struct bufferevent *event;
|
||||
|
||||
int log_fd;
|
||||
|
||||
|
25
tty-keys.c
25
tty-keys.c
@ -1,4 +1,4 @@
|
||||
/* $Id: tty-keys.c,v 1.38 2009-10-28 23:05:01 tcunha Exp $ */
|
||||
/* $Id: tty-keys.c,v 1.39 2009-11-08 22:58:38 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -299,18 +299,20 @@ tty_keys_next(struct tty *tty, int *key, struct mouse_event *mouse)
|
||||
struct tty_key *tk;
|
||||
struct timeval tv;
|
||||
char *buf;
|
||||
u_char ch;
|
||||
size_t len, size;
|
||||
cc_t bspace;
|
||||
|
||||
buf = BUFFER_OUT(tty->in);
|
||||
len = BUFFER_USED(tty->in);
|
||||
buf = EVBUFFER_DATA(tty->event->input);
|
||||
len = EVBUFFER_LENGTH(tty->event->input);
|
||||
if (len == 0)
|
||||
return (1);
|
||||
log_debug("keys are %zu (%.*s)", len, (int) len, buf);
|
||||
|
||||
/* If a normal key, return it. */
|
||||
if (*buf != '\033') {
|
||||
*key = buffer_read8(tty->in);
|
||||
bufferevent_read(tty->event, &ch, 1);
|
||||
*key = ch;
|
||||
|
||||
/*
|
||||
* Check for backspace key using termios VERASE - the terminfo
|
||||
@ -326,7 +328,7 @@ tty_keys_next(struct tty *tty, int *key, struct mouse_event *mouse)
|
||||
/* Look for matching key string and return if found. */
|
||||
tk = tty_keys_find(tty, buf + 1, len - 1, &size);
|
||||
if (tk != NULL) {
|
||||
buffer_remove(tty->in, size + 1);
|
||||
evbuffer_drain(tty->event->input, size + 1);
|
||||
*key = tk->key;
|
||||
goto found;
|
||||
}
|
||||
@ -334,14 +336,14 @@ tty_keys_next(struct tty *tty, int *key, struct mouse_event *mouse)
|
||||
/* Not found. Is this a mouse key press? */
|
||||
*key = tty_keys_mouse(buf, len, &size, mouse);
|
||||
if (*key != KEYC_NONE) {
|
||||
buffer_remove(tty->in, size);
|
||||
evbuffer_drain(tty->event->input, size);
|
||||
goto found;
|
||||
}
|
||||
|
||||
/* Not found. Try to parse a key with an xterm-style modifier. */
|
||||
*key = xterm_keys_find(buf, len, &size);
|
||||
if (*key != KEYC_NONE) {
|
||||
buffer_remove(tty->in, size);
|
||||
evbuffer_drain(tty->event->input, size);
|
||||
goto found;
|
||||
}
|
||||
|
||||
@ -363,8 +365,9 @@ tty_keys_next(struct tty *tty, int *key, struct mouse_event *mouse)
|
||||
|
||||
/* Is there a normal key following? */
|
||||
if (len != 0 && *buf != '\033') {
|
||||
buffer_remove(tty->in, 1);
|
||||
*key = buffer_read8(tty->in) | KEYC_ESCAPE;
|
||||
evbuffer_drain(tty->event->input, 1);
|
||||
bufferevent_read(tty->event, &ch, 1);
|
||||
*key = ch | KEYC_ESCAPE;
|
||||
goto found;
|
||||
}
|
||||
|
||||
@ -372,7 +375,7 @@ tty_keys_next(struct tty *tty, int *key, struct mouse_event *mouse)
|
||||
if (len > 1) {
|
||||
tk = tty_keys_find(tty, buf + 1, len - 1, &size);
|
||||
if (tk != NULL) {
|
||||
buffer_remove(tty->in, size + 2);
|
||||
evbuffer_drain(tty->event->input, size + 2);
|
||||
*key = tk->key | KEYC_ESCAPE;
|
||||
goto found;
|
||||
}
|
||||
@ -385,7 +388,7 @@ tty_keys_next(struct tty *tty, int *key, struct mouse_event *mouse)
|
||||
return (1);
|
||||
|
||||
/* Give up and return the escape. */
|
||||
buffer_remove(tty->in, 1);
|
||||
evbuffer_drain(tty->event->input, 1);
|
||||
*key = '\033';
|
||||
|
||||
found:
|
||||
|
32
tty.c
32
tty.c
@ -1,4 +1,4 @@
|
||||
/* $Id: tty.c,v 1.169 2009-11-04 23:10:43 tcunha Exp $ */
|
||||
/* $Id: tty.c,v 1.170 2009-11-08 22:58:38 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -28,6 +28,8 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
void tty_error_callback(struct bufferevent *, short, void *);
|
||||
|
||||
void tty_fill_acs(struct tty *);
|
||||
|
||||
int tty_try_256(struct tty *, u_char, const char *);
|
||||
@ -108,11 +110,11 @@ tty_open(struct tty *tty, const char *overrides, char **cause)
|
||||
}
|
||||
tty->flags |= TTY_OPENED;
|
||||
|
||||
tty->in = buffer_create(BUFSIZ);
|
||||
tty->out = buffer_create(BUFSIZ);
|
||||
|
||||
tty->flags &= ~(TTY_NOCURSOR|TTY_FREEZE|TTY_ESCAPE);
|
||||
|
||||
tty->event = bufferevent_new(
|
||||
tty->fd, NULL, NULL, tty_error_callback, tty);
|
||||
|
||||
tty_start_tty(tty);
|
||||
|
||||
tty_keys_init(tty);
|
||||
@ -122,6 +124,13 @@ tty_open(struct tty *tty, const char *overrides, char **cause)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
tty_error_callback(
|
||||
unused struct bufferevent *bufev, unused short what, unused void *data)
|
||||
{
|
||||
fatalx("lost terminal");
|
||||
}
|
||||
|
||||
void
|
||||
tty_start_tty(struct tty *tty)
|
||||
{
|
||||
@ -139,6 +148,8 @@ tty_start_tty(struct tty *tty)
|
||||
if (fcntl(tty->fd, F_SETFL, mode|O_NONBLOCK) == -1)
|
||||
fatal("fcntl failed");
|
||||
|
||||
bufferevent_enable(tty->event, EV_READ|EV_WRITE);
|
||||
|
||||
if (tcgetattr(tty->fd, &tty->tio) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
memcpy(&tio, &tty->tio, sizeof tio);
|
||||
@ -192,6 +203,8 @@ tty_stop_tty(struct tty *tty)
|
||||
return;
|
||||
tty->flags &= ~TTY_STARTED;
|
||||
|
||||
bufferevent_disable(tty->event, EV_READ|EV_WRITE);
|
||||
|
||||
/*
|
||||
* Be flexible about error handling and try not kill the server just
|
||||
* because the fd is invalid. Things like ssh -t can easily leave us
|
||||
@ -254,12 +267,11 @@ tty_close(struct tty *tty)
|
||||
tty_stop_tty(tty);
|
||||
|
||||
if (tty->flags & TTY_OPENED) {
|
||||
bufferevent_free(tty->event);
|
||||
|
||||
tty_term_free(tty->term);
|
||||
tty_keys_free(tty);
|
||||
|
||||
buffer_destroy(tty->in);
|
||||
buffer_destroy(tty->out);
|
||||
|
||||
tty->flags &= ~TTY_OPENED;
|
||||
}
|
||||
|
||||
@ -313,7 +325,7 @@ tty_puts(struct tty *tty, const char *s)
|
||||
{
|
||||
if (*s == '\0')
|
||||
return;
|
||||
buffer_write(tty->out, s, strlen(s));
|
||||
bufferevent_write(tty->event, s, strlen(s));
|
||||
|
||||
if (tty->log_fd != -1)
|
||||
write(tty->log_fd, s, strlen(s));
|
||||
@ -326,7 +338,7 @@ tty_putc(struct tty *tty, u_char ch)
|
||||
|
||||
if (tty->cell.attr & GRID_ATTR_CHARSET)
|
||||
ch = tty_get_acs(tty, ch);
|
||||
buffer_write8(tty->out, ch);
|
||||
bufferevent_write(tty->event, &ch, 1);
|
||||
|
||||
if (ch >= 0x20 && ch != 0x7f) {
|
||||
sx = tty->sx;
|
||||
@ -353,7 +365,7 @@ tty_pututf8(struct tty *tty, const struct grid_utf8 *gu)
|
||||
for (i = 0; i < UTF8_SIZE; i++) {
|
||||
if (gu->data[i] == 0xff)
|
||||
break;
|
||||
buffer_write8(tty->out, gu->data[i]);
|
||||
bufferevent_write(tty->event, &gu->data[i], 1);
|
||||
if (tty->log_fd != -1)
|
||||
write(tty->log_fd, &gu->data[i], 1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user