=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/server.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- src/usr.bin/tmux/server.c 2009/08/10 19:42:03 1.17 +++ src/usr.bin/tmux/server.c 2009/08/11 17:18:35 1.18 @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.17 2009/08/10 19:42:03 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.18 2009/08/11 17:18:35 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -85,9 +85,7 @@ fatal("fcntl failed"); c = xcalloc(1, sizeof *c); - c->fd = fd; - c->in = buffer_create(BUFSIZ); - c->out = buffer_create(BUFSIZ); + imsg_init(&c->ibuf, fd); ARRAY_INIT(&c->prompt_hdata); @@ -672,10 +670,10 @@ if (c == NULL) (*pfd)->fd = -1; else { - (*pfd)->fd = c->fd; + (*pfd)->fd = c->ibuf.fd; if (!(c->flags & CLIENT_BAD)) - (*pfd)->events = POLLIN; - if (BUFFER_USED(c->out) > 0) + (*pfd)->events |= POLLIN; + if (c->ibuf.w.queued > 0) (*pfd)->events |= POLLOUT; } (*pfd)++; @@ -718,17 +716,32 @@ c = ARRAY_ITEM(&clients, i); if (c != NULL) { - if (buffer_poll(*pfd, c->in, c->out) != 0) { + if ((*pfd)->revents & (POLLERR|POLLNVAL|POLLHUP)) { server_lost_client(c); (*pfd) += 2; continue; - } else if (c->flags & CLIENT_BAD) { - if (BUFFER_USED(c->out) == 0) + } + + if ((*pfd)->revents & POLLOUT) { + if (msgbuf_write(&c->ibuf.w) < 0) { server_lost_client(c); + (*pfd) += 2; + continue; + } + } + + if (c->flags & CLIENT_BAD) { + if (c->ibuf.w.queued == 0) + server_lost_client(c); (*pfd) += 2; - continue; - } else - server_msg_dispatch(c); + continue; + } else if ((*pfd)->revents & POLLIN) { + if (server_msg_dispatch(c) != 0) { + server_lost_client(c); + (*pfd) += 2; + continue; + } + } } (*pfd)++; @@ -910,9 +923,8 @@ if (c->cwd != NULL) xfree(c->cwd); - close(c->fd); - buffer_destroy(c->in); - buffer_destroy(c->out); + close(c->ibuf.fd); + imsg_clear(&c->ibuf); xfree(c); recalculate_sizes();