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.
This commit is contained in:
Nicholas Marriott 2009-11-04 23:12:43 +00:00
parent 6a6a42aa3a
commit b3c4956efe
4 changed files with 22 additions and 30 deletions

View File

@ -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:

View File

@ -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);
}

View File

@ -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);

2
tmux.h
View File

@ -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 *);