summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/server-client.c25
-rw-r--r--usr.bin/tmux/server-window.c5
-rw-r--r--usr.bin/tmux/tmux.h6
-rw-r--r--usr.bin/tmux/tty-keys.c25
-rw-r--r--usr.bin/tmux/tty.c32
5 files changed, 43 insertions, 50 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index a2a6b495434..61c85367180 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.12 2009/11/04 20:50:11 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.13 2009/11/04 21:47:42 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -136,8 +136,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);
@@ -172,18 +171,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);
}
}
@@ -209,14 +196,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;
diff --git a/usr.bin/tmux/server-window.c b/usr.bin/tmux/server-window.c
index 2bd3a98dc56..aef03280a16 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.6 2009/11/04 20:59:22 nicm Exp $ */
+/* $OpenBSD: server-window.c,v 1.7 2009/11/04 21:47:42 nicm 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);
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index e7cefe869e9..9ed46d25707 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.160 2009/11/04 21:04:43 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.161 2009/11/04 21:47:42 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1000,9 +1000,7 @@ struct tty {
struct tty_term *term;
int fd;
- struct event event;
- struct buffer *in;
- struct buffer *out;
+ struct bufferevent *event;
int log_fd;
diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c
index 6e66788f377..36b850f15d7 100644
--- a/usr.bin/tmux/tty-keys.c
+++ b/usr.bin/tmux/tty-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty-keys.c,v 1.12 2009/10/26 17:59:46 nicm Exp $ */
+/* $OpenBSD: tty-keys.c,v 1.13 2009/11/04 21:47:42 nicm 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:
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index c07ac40a83e..d2296f17d4c 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.65 2009/11/04 15:59:27 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.66 2009/11/04 21:47:42 nicm 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);
@@ -123,6 +125,13 @@ tty_open(struct tty *tty, const char *overrides, char **cause)
}
void
+tty_error_callback(
+ unused struct bufferevent *bufev, unused short what, unused void *data)
+{
+ fatalx("lost terminal");
+}
+
+void
tty_start_tty(struct tty *tty)
{
struct termios tio;
@@ -136,6 +145,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);
@@ -187,6 +198,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
@@ -249,12 +262,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;
}
@@ -308,7 +320,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));
@@ -321,7 +333,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;
@@ -348,7 +360,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);
}