mirror of
https://github.com/tmux/tmux.git
synced 2025-09-03 06:17:04 +00:00
Sync OpenBSD patchset 495:
Switch tty fds over to a bufferevent.
This commit is contained in:
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user