diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-04 20:50:12 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-04 20:50:12 +0000 |
commit | 891ac5e256beff387c5a745dc912f221cc17024e (patch) | |
tree | bfc8c4cbc6c1f75a512e6e7d9d8b73e6b5d7de93 /usr.bin/tmux/server-client.c | |
parent | e50bf28f99a17da4b270d84d66bd20c7e271f67b (diff) |
Initial changes to move tmux to libevent.
This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.
Moving the server stuff over to bufferevents and timers and so on will come
later.
Diffstat (limited to 'usr.bin/tmux/server-client.c')
-rw-r--r-- | usr.bin/tmux/server-client.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 77e48942847..a2a6b495434 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.11 2009/11/03 22:40:40 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.12 2009/11/04 20:50:11 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -18,6 +18,7 @@ #include <sys/types.h> +#include <event.h> #include <fcntl.h> #include <string.h> #include <time.h> @@ -134,7 +135,9 @@ 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); @@ -162,25 +165,31 @@ server_client_prepare(void) events = 0; if (!(c->flags & CLIENT_BAD)) - events |= POLLIN; + events |= EV_READ; if (c->ibuf.w.queued > 0) - events |= POLLOUT; - server_poll_add(c->ibuf.fd, events, server_client_callback, c); + events |= EV_WRITE; + event_del(&c->event); + 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 = POLLIN; + events = EV_READ; if (BUFFER_USED(c->tty.out) > 0) - events |= POLLOUT; - server_poll_add(c->tty.fd, events, server_client_callback, c); + 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); } } /* Process a single client event. */ void -server_client_callback(int fd, int events, void *data) +server_client_callback(int fd, short events, void *data) { struct client *c = data; @@ -188,10 +197,7 @@ server_client_callback(int fd, int events, void *data) return; if (fd == c->ibuf.fd) { - if (events & (POLLERR|POLLNVAL|POLLHUP)) - goto client_lost; - - if (events & POLLOUT && msgbuf_write(&c->ibuf.w) < 0) + if (events & EV_WRITE && msgbuf_write(&c->ibuf.w) < 0) goto client_lost; if (c->flags & CLIENT_BAD) { @@ -200,7 +206,7 @@ server_client_callback(int fd, int events, void *data) return; } - if (events & POLLIN && server_client_msg_dispatch(c) != 0) + if (events & EV_READ && server_client_msg_dispatch(c) != 0) goto client_lost; } @@ -211,7 +217,7 @@ server_client_callback(int fd, int events, void *data) if (buffer_poll(fd, events, c->tty.in, c->tty.out) != 0) goto client_lost; } - + return; client_lost: @@ -424,7 +430,7 @@ server_client_check_redraw(struct client *c) if (c->flags & (CLIENT_REDRAW|CLIENT_STATUS)) { if (options_get_number(&s->options, "set-titles")) server_client_set_title(c); - + if (c->message_string != NULL) redraw = status_message_redraw(c); else if (c->prompt_string != NULL) |