=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/server.c,v retrieving revision 1.48 retrieving revision 1.49 diff -c -r1.48 -r1.49 *** src/usr.bin/tmux/server.c 2009/10/10 14:51:16 1.48 --- src/usr.bin/tmux/server.c 2009/10/10 15:03:01 1.49 *************** *** 1,4 **** ! /* $OpenBSD: server.c,v 1.48 2009/10/10 14:51:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: server.c,v 1.49 2009/10/10 15:03:01 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 72,77 **** --- 72,81 ---- void server_handle_windows(void); void server_fill_clients(void); void server_handle_clients(void); + void server_fill_jobs(void); + void server_fill_jobs1(struct jobs *); + void server_handle_jobs(void); + void server_handle_jobs1(struct jobs *); void server_accept_client(int); void server_handle_client(struct client *); void server_handle_window(struct window *, struct window_pane *); *************** *** 190,196 **** --- 194,202 ---- c->session = NULL; c->tty.sx = 80; c->tty.sy = 24; + screen_init(&c->status, c->tty.sx, 1, 0); + job_tree_init(&c->status_jobs); c->message_string = NULL; *************** *** 370,375 **** --- 376,382 ---- server_poll_add(srv_fd, POLLIN); /* Fill window and client sockets. */ + server_fill_jobs(); server_fill_windows(); server_fill_clients(); *************** *** 412,417 **** --- 419,425 ---- * windows, so windows must come first to avoid messing up by * increasing the array size. */ + server_handle_jobs(); server_handle_windows(); server_handle_clients(); *************** *** 648,654 **** template = options_get_string(&s->options, "set-titles-string"); ! title = status_replace(c->session, template, time(NULL)); if (c->title == NULL || strcmp(title, c->title) != 0) { if (c->title != NULL) xfree(c->title); --- 656,662 ---- template = options_get_string(&s->options, "set-titles-string"); ! title = status_replace(c, template, time(NULL)); if (c->title == NULL || strcmp(title, c->title) != 0) { if (c->title != NULL) xfree(c->title); *************** *** 663,668 **** --- 671,677 ---- server_check_timers(struct client *c) { struct session *s; + struct job *job; struct timeval tv; u_int interval; *************** *** 694,701 **** if (interval == 0) return; if (tv.tv_sec < c->status_timer.tv_sec || ! ((u_int) tv.tv_sec) - c->status_timer.tv_sec >= interval) c->flags |= CLIENT_STATUS; } /* Fill client pollfds. */ --- 703,714 ---- if (interval == 0) return; if (tv.tv_sec < c->status_timer.tv_sec || ! ((u_int) tv.tv_sec) - c->status_timer.tv_sec >= interval) { ! /* Run the jobs for this client and schedule for redraw. */ ! RB_FOREACH(job, jobs, &c->status_jobs) ! job_run(job); c->flags |= CLIENT_STATUS; + } } /* Fill client pollfds. */ *************** *** 747,752 **** --- 760,825 ---- } } + /* Fill in job fds. */ + void + server_fill_jobs(void) + { + struct client *c; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c != NULL) + server_fill_jobs1(&c->status_jobs); + } + } + + void + server_fill_jobs1(struct jobs *jobs) + { + struct job *job; + + RB_FOREACH(job, jobs, jobs) { + if (job->fd == -1) + continue; + server_poll_add(job->fd, POLLIN); + } + } + + /* Handle job fds. */ + void + server_handle_jobs(void) + { + struct client *c; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c != NULL) + server_handle_jobs1(&c->status_jobs); + } + } + + void + server_handle_jobs1(struct jobs *jobs) + { + struct job *job; + struct pollfd *pfd; + + RB_FOREACH(job, jobs, jobs) { + if (job->fd == -1) + continue; + if ((pfd = server_poll_lookup(job->fd)) == NULL) + continue; + if (buffer_poll(pfd, job->out, NULL) != 0) { + close(job->fd); + job->fd = -1; + if (job->callbackfn != NULL) + job->callbackfn(job); + } + } + } + /* Handle client pollfds. */ void server_handle_clients(void) *************** *** 991,996 **** --- 1064,1070 ---- tty_free(&c->tty); screen_free(&c->status); + job_tree_free(&c->status_jobs); if (c->title != NULL) xfree(c->title);