From 07b0ea03c33893bd2b104db5ea4e1397f92e0477 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 27 Oct 2015 13:23:24 +0000 Subject: Break the common process set up, event loop and imsg dispatch code between server and client out into a separate internal API. This will make it easier to add another process. --- server-fn.c | 64 +++++++------------------------------------------------------ 1 file changed, 7 insertions(+), 57 deletions(-) (limited to 'server-fn.c') diff --git a/server-fn.c b/server-fn.c index a31a3772..095535ab 100644 --- a/server-fn.c +++ b/server-fn.c @@ -17,7 +17,10 @@ */ #include +#include +#include +#include #include #include #include @@ -47,43 +50,6 @@ server_fill_environ(struct session *s, struct environ *env) environ_set(env, "TMUX", var); } -void -server_write_ready(struct client *c) -{ - if (c->flags & CLIENT_CONTROL) - return; - server_write_client(c, MSG_READY, NULL, 0); -} - -int -server_write_client(struct client *c, enum msgtype type, const void *buf, - size_t len) -{ - struct imsgbuf *ibuf = &c->ibuf; - int error; - - if (c->flags & CLIENT_BAD) - return (-1); - log_debug("writing %d to client %p", type, c); - error = imsg_compose(ibuf, type, PROTOCOL_VERSION, -1, -1, - (void *) buf, len); - if (error == 1) - server_update_event(c); - return (error == 1 ? 0 : -1); -} - -void -server_write_session(struct session *s, enum msgtype type, const void *buf, - size_t len) -{ - struct client *c; - - TAILQ_FOREACH(c, &clients, entry) { - if (c->session == s) - server_write_client(c, type, buf, len); - } -} - void server_redraw_client(struct client *c) { @@ -227,7 +193,7 @@ server_lock_client(struct client *c) tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_E3)); c->flags |= CLIENT_SUSPENDED; - server_write_client(c, MSG_LOCK, cmd, strlen(cmd) + 1); + proc_send_s(c->peer, MSG_LOCK, cmd); } void @@ -484,22 +450,6 @@ server_callback_identify(unused int fd, unused short events, void *data) server_clear_identify(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; - if (event_initialized(&c->event)) - event_del(&c->event); - event_set(&c->event, c->ibuf.fd, events, server_client_callback, c); - event_add(&c->event, NULL); -} - /* Push stdout to client if possible. */ void server_push_stdout(struct client *c) @@ -516,7 +466,7 @@ server_push_stdout(struct client *c) memcpy(data.data, EVBUFFER_DATA(c->stdout_data), size); data.size = size; - if (server_write_client(c, MSG_STDOUT, &data, sizeof data) == 0) + if (proc_send(c->peer, MSG_STDOUT, -1, &data, sizeof data) == 0) evbuffer_drain(c->stdout_data, size); } @@ -540,7 +490,7 @@ server_push_stderr(struct client *c) memcpy(data.data, EVBUFFER_DATA(c->stderr_data), size); data.size = size; - if (server_write_client(c, MSG_STDERR, &data, sizeof data) == 0) + if (proc_send(c->peer, MSG_STDERR, -1, &data, sizeof data) == 0) evbuffer_drain(c->stderr_data, size); } @@ -570,7 +520,7 @@ server_set_stdin_callback(struct client *c, void (*cb)(struct client *, int, if (c->stdin_closed) c->stdin_callback(c, 1, c->stdin_callback_data); - server_write_client(c, MSG_STDIN, NULL, 0); + proc_send(c->peer, MSG_STDIN, -1, NULL, 0); return (0); } -- cgit From 44657bf932b068aff5ce1019a4e8a2e7b00b5321 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 27 Oct 2015 15:58:42 +0000 Subject: Move struct options into options.c. --- server-fn.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'server-fn.c') diff --git a/server-fn.c b/server-fn.c index 095535ab..e9a04cb5 100644 --- a/server-fn.c +++ b/server-fn.c @@ -39,7 +39,7 @@ server_fill_environ(struct session *s, struct environ *env) long pid; if (s != NULL) { - term = options_get_string(&global_options, "default-terminal"); + term = options_get_string(global_options, "default-terminal"); environ_set(env, "TERM", term); idx = s->id; @@ -183,7 +183,7 @@ server_lock_client(struct client *c) if (c->flags & CLIENT_SUSPENDED) return; - cmd = options_get_string(&c->session->options, "lock-command"); + cmd = options_get_string(c->session->options, "lock-command"); if (strlen(cmd) + 1 > MAX_IMSGSIZE - IMSG_HEADER_SIZE) return; @@ -219,7 +219,7 @@ server_kill_window(struct window *w) server_redraw_session_group(s); } - if (options_get_number(&s->options, "renumber-windows")) { + if (options_get_number(s->options, "renumber-windows")) { if ((sg = session_group_find(s)) != NULL) { TAILQ_FOREACH(target_s, &sg->sessions, gentry) session_renumber_windows(target_s); @@ -272,7 +272,7 @@ server_link_window(struct session *src, struct winlink *srcwl, } if (dstidx == -1) - dstidx = -1 - options_get_number(&dst->options, "base-index"); + dstidx = -1 - options_get_number(dst->options, "base-index"); dstwl = session_attach(dst, srcwl->window, dstidx, cause); if (dstwl == NULL) return (-1); @@ -308,7 +308,7 @@ server_destroy_pane(struct window_pane *wp) wp->fd = -1; } - if (options_get_number(&w->options, "remain-on-exit")) { + if (options_get_number(w->options, "remain-on-exit")) { if (old_fd == -1) return; screen_write_start(&ctx, wp, &wp->base); @@ -371,7 +371,7 @@ server_destroy_session(struct session *s) struct client *c; struct session *s_new; - if (!options_get_number(&s->options, "detach-on-destroy")) + if (!options_get_number(s->options, "detach-on-destroy")) s_new = server_next_session(s); else s_new = NULL; @@ -407,7 +407,7 @@ server_check_unattached(void) RB_FOREACH(s, sessions, &sessions) { if (!(s->flags & SESSION_UNATTACHED)) continue; - if (options_get_number (&s->options, "destroy-unattached")) + if (options_get_number (s->options, "destroy-unattached")) session_destroy(s); } } @@ -418,7 +418,7 @@ server_set_identify(struct client *c) struct timeval tv; int delay; - delay = options_get_number(&c->session->options, "display-panes-time"); + delay = options_get_number(c->session->options, "display-panes-time"); tv.tv_sec = delay / 1000; tv.tv_usec = (delay % 1000) * 1000L; -- cgit