From b3c4956efeb62bae3c9ac64eab2371bb6384623a Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 4 Nov 2009 23:12:43 +0000 Subject: [PATCH] Don't reenlist the client imsg event every loop, instead have a small function to it and call it after the event triggers or after a imsg is added. --- server-client.c | 28 +++------------------------- server-fn.c | 16 ++++++++++++++++ server.c | 6 ++---- tmux.h | 2 +- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/server-client.c b/server-client.c index f839c305..2d5701f5 100644 --- a/server-client.c +++ b/server-client.c @@ -61,6 +61,7 @@ server_client_create(int fd) c = xcalloc(1, sizeof *c); c->references = 0; imsg_init(&c->ibuf, fd); + server_update_event(c); if (gettimeofday(&c->creation_time, NULL) != 0) fatal("gettimeofday failed"); @@ -150,30 +151,6 @@ server_client_lost(struct client *c) recalculate_sizes(); } -/* Register clients for poll. */ -void -server_client_prepare(void) -{ - struct client *c; - u_int i; - int events; - - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - if ((c = ARRAY_ITEM(&clients, i)) == NULL) - continue; - - events = 0; - if (!(c->flags & CLIENT_BAD)) - events |= EV_READ; - if (c->ibuf.w.queued > 0) - events |= EV_WRITE; - event_del(&c->event); - event_set(&c->event, - c->ibuf.fd, events, server_client_callback, c); - event_add(&c->event, NULL); - } -} - /* Process a single client event. */ void server_client_callback(int fd, short events, void *data) @@ -196,7 +173,8 @@ server_client_callback(int fd, short events, void *data) if (events & EV_READ && server_client_msg_dispatch(c) != 0) goto client_lost; } - + + server_update_event(c); return; client_lost: diff --git a/server-fn.c b/server-fn.c index f4f71980..66845b91 100644 --- a/server-fn.c +++ b/server-fn.c @@ -59,6 +59,7 @@ server_write_client( return; log_debug("writing %d to client %d", type, c->ibuf.fd); imsg_compose(ibuf, type, PROTOCOL_VERSION, -1, -1, (void *) buf, len); + server_update_event(c); } void @@ -371,3 +372,18 @@ server_clear_identify(struct client *c) server_redraw_client(c); } } + +void +server_update_event(struct client *c) +{ + short events; + + events = 0; + if (!(c->flags & CLIENT_BAD)) + events |= EV_READ; + if (c->ibuf.w.queued > 0) + events |= EV_WRITE; + event_del(&c->event); + event_set(&c->event, c->ibuf.fd, events, server_client_callback, c); + event_add(&c->event, NULL); +} diff --git a/server.c b/server.c index eb215009..4c1f9cea 100644 --- a/server.c +++ b/server.c @@ -160,11 +160,11 @@ server_start(char *path) log_debug("socket path %s", socket_path); setproctitle("server (%s)", rpathbuf); + event_init(); + server_fd = server_create_socket(); server_client_create(pair[1]); - event_init(); - if (access(SYSTEM_CFG, R_OK) == 0) { if (load_cfg(SYSTEM_CFG, NULL, &cause) != 0) goto error; @@ -215,8 +215,6 @@ server_loop(void) while (!server_should_shutdown()) { server_update_socket(); - server_client_prepare(); - event_loopexit(&tv); event_loop(EVLOOP_ONCE); diff --git a/tmux.h b/tmux.h index f5056e1f..4603af4d 100644 --- a/tmux.h +++ b/tmux.h @@ -1564,7 +1564,6 @@ void server_signal_clear(void); /* server-client.c */ void server_client_create(int); void server_client_lost(struct client *); -void server_client_prepare(void); void server_client_callback(int, short, void *); void server_client_loop(void); @@ -1598,6 +1597,7 @@ void server_destroy_session_group(struct session *); void server_destroy_session(struct session *); void server_set_identify(struct client *); void server_clear_identify(struct client *); +void server_update_event(struct client *); /* status.c */ int status_redraw(struct client *);