From f4514f5c603ccffb4741e1009624537b06658a3b Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Wed, 28 Oct 2009 23:14:15 +0000 Subject: [PATCH] Sync OpenBSD patchset 468: Move the poll registration functions into the server-*.c files. --- server-client.c | 32 ++++++++++++++++- server-job.c | 15 +++++++- server-window.c | 35 ++++++++++++++++++- server.c | 93 +++---------------------------------------------- tmux.h | 6 +++- 5 files changed, 89 insertions(+), 92 deletions(-) diff --git a/server-client.c b/server-client.c index 254766a1..9acfa4c9 100644 --- a/server-client.c +++ b/server-client.c @@ -1,4 +1,4 @@ -/* $Id: server-client.c,v 1.9 2009-10-28 23:12:38 tcunha Exp $ */ +/* $Id: server-client.c,v 1.10 2009-10-28 23:14:15 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -146,6 +146,36 @@ 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 |= POLLIN; + if (c->ibuf.w.queued > 0) + events |= POLLOUT; + server_poll_add(c->ibuf.fd, events, server_client_callback, c); + + if (c->tty.fd == -1) + continue; + if (c->flags & CLIENT_SUSPENDED || c->session == NULL) + continue; + events = POLLIN; + if (BUFFER_USED(c->tty.out) > 0) + events |= POLLOUT; + server_poll_add(c->tty.fd, events, server_client_callback, c); + } +} + /* Process a single client event. */ void server_client_callback(int fd, int events, void *data) diff --git a/server-job.c b/server-job.c index a3d4d0dd..366ab2df 100644 --- a/server-job.c +++ b/server-job.c @@ -1,4 +1,4 @@ -/* $Id: server-job.c,v 1.1 2009-10-23 17:49:47 tcunha Exp $ */ +/* $Id: server-job.c,v 1.2 2009-10-28 23:14:15 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -22,6 +22,19 @@ #include "tmux.h" +/* Register jobs for poll. */ +void +server_job_prepare(void) +{ + struct job *job; + + SLIST_FOREACH(job, &all_jobs, lentry) { + if (job->fd == -1) + continue; + server_poll_add(job->fd, POLLIN, server_job_callback, job); + } +} + /* Process a single job event. */ void server_job_callback(int fd, int events, void *data) diff --git a/server-window.c b/server-window.c index fe554afd..0c57b990 100644 --- a/server-window.c +++ b/server-window.c @@ -1,4 +1,4 @@ -/* $Id: server-window.c,v 1.1 2009-10-23 17:49:47 tcunha Exp $ */ +/* $Id: server-window.c,v 1.2 2009-10-28 23:14:15 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -28,6 +28,39 @@ int server_window_check_content( struct session *, struct window *, struct window_pane *); void server_window_check_alive(struct window *); +/* Register windows for poll. */ +void +server_window_prepare(void) +{ + struct window *w; + struct window_pane *wp; + u_int i; + int events; + + for (i = 0; i < ARRAY_LENGTH(&windows); i++) { + if ((w = ARRAY_ITEM(&windows, i)) == NULL) + continue; + + TAILQ_FOREACH(wp, &w->panes, entry) { + if (wp->fd == -1) + continue; + events = POLLIN; + if (BUFFER_USED(wp->out) > 0) + events |= POLLOUT; + server_poll_add( + wp->fd, events, server_window_callback, wp); + + if (wp->pipe_fd == -1) + continue; + events = 0; + if (BUFFER_USED(wp->pipe_buf) > 0) + events |= POLLOUT; + server_poll_add( + wp->pipe_fd, events, server_window_callback, wp); + } + } +} + /* Process a single window pane event. */ void server_window_callback(int fd, int events, void *data) diff --git a/server.c b/server.c index 4e6b7c8c..faf9096b 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.213 2009-10-28 23:12:38 tcunha Exp $ */ +/* $Id: server.c,v 1.214 2009-10-28 23:14:15 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -58,7 +58,6 @@ RB_HEAD(poll_items, poll_item) poll_items; int server_poll_cmp(struct poll_item *, struct poll_item *); struct poll_item*server_poll_lookup(int); -void server_poll_add(int, int, void (*)(int, int, void *), void *); struct pollfd *server_poll_flatten(int *); void server_poll_dispatch(struct pollfd *, int); void server_poll_reset(void); @@ -71,9 +70,6 @@ int server_main(int); void server_shutdown(void); int server_should_shutdown(void); void server_child_signal(void); -void server_fill_windows(void); -void server_fill_clients(void); -void server_fill_jobs(void); void server_clean_dead(void); void server_second_timers(void); void server_lock_server(void); @@ -349,10 +345,10 @@ server_main(int srv_fd) server_poll_add(srv_fd, POLLIN, server_callback, NULL); /* Fill window and client sockets. */ - server_fill_jobs(); - server_fill_windows(); - server_fill_clients(); - + server_job_prepare(); + server_window_prepare(); + server_client_prepare(); + /* Update socket permissions. */ xtimeout = INFTIM; if (server_update_socket() != 0) @@ -508,85 +504,6 @@ server_child_signal(void) } } -/* Fill window pollfds. */ -void -server_fill_windows(void) -{ - struct window *w; - struct window_pane *wp; - u_int i; - int events; - - for (i = 0; i < ARRAY_LENGTH(&windows); i++) { - w = ARRAY_ITEM(&windows, i); - if (w == NULL) - continue; - - TAILQ_FOREACH(wp, &w->panes, entry) { - if (wp->fd == -1) - continue; - events = POLLIN; - if (BUFFER_USED(wp->out) > 0) - events |= POLLOUT; - server_poll_add( - wp->fd, events, server_window_callback, wp); - - if (wp->pipe_fd == -1) - continue; - events = 0; - if (BUFFER_USED(wp->pipe_buf) > 0) - events |= POLLOUT; - server_poll_add( - wp->pipe_fd, events, server_window_callback, wp); - } - } -} - -/* Fill client pollfds. */ -void -server_fill_clients(void) -{ - struct client *c; - u_int i; - int events; - - for (i = 0; i < ARRAY_LENGTH(&clients); i++) { - c = ARRAY_ITEM(&clients, i); - - if (c != NULL) { - events = 0; - if (!(c->flags & CLIENT_BAD)) - events |= POLLIN; - if (c->ibuf.w.queued > 0) - events |= POLLOUT; - server_poll_add( - c->ibuf.fd, events, server_client_callback, c); - } - - if (c != NULL && !(c->flags & CLIENT_SUSPENDED) && - c->tty.fd != -1 && c->session != NULL) { - events = POLLIN; - if (BUFFER_USED(c->tty.out) > 0) - events |= POLLOUT; - server_poll_add( - c->tty.fd, events, server_client_callback, c); - } - } -} - -/* Fill in job fds. */ -void -server_fill_jobs(void) -{ - struct job *job; - - SLIST_FOREACH(job, &all_jobs, lentry) { - if (job->fd == -1) - continue; - server_poll_add(job->fd, POLLIN, server_job_callback, job); - } -} - /* Free dead, unreferenced clients and sessions. */ void server_clean_dead(void) diff --git a/tmux.h b/tmux.h index ad458836..d54ee216 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.488 2009-10-28 23:03:51 tcunha Exp $ */ +/* $Id: tmux.h,v 1.489 2009-10-28 23:14:15 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1572,18 +1572,22 @@ const char *key_string_lookup_key(int); extern struct clients clients; extern struct clients dead_clients; int server_start(char *); +void server_poll_add(int, int, void (*)(int, int, void *), 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, int, void *); void server_client_loop(void); /* server-job.c */ +void server_job_prepare(void); void server_job_callback(int, int, void *); void server_job_loop(void); /* server-window.c */ +void server_window_prepare(void); void server_window_callback(int, int, void *); void server_window_loop(void);