Sync OpenBSD patchset 468:

Move the poll registration functions into the server-*.c files.
This commit is contained in:
Tiago Cunha 2009-10-28 23:14:15 +00:00
parent a5acabd923
commit f4514f5c60
5 changed files with 89 additions and 92 deletions

View File

@ -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 <nicm@users.sourceforge.net>
@ -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)

View File

@ -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 <nicm@users.sourceforge.net>
@ -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)

View File

@ -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 <nicm@users.sourceforge.net>
@ -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)

View File

@ -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 <nicm@users.sourceforge.net>
@ -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)

6
tmux.h
View File

@ -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 <nicm@users.sourceforge.net>
@ -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);