diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-04 22:57:50 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-04 22:57:50 +0000 |
commit | 54e6bb578c335ce9eba3f9b5343e927f9baff018 (patch) | |
tree | 797011b4d0d03bca0b6b6b54e54965286ea24def /usr.bin/tmux/client.c | |
parent | 04b901b7d93b7bbd584eb7867ee28c798fe014bb (diff) |
Move some common code into a function.
Diffstat (limited to 'usr.bin/tmux/client.c')
-rw-r--r-- | usr.bin/tmux/client.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/usr.bin/tmux/client.c b/usr.bin/tmux/client.c index f1d5c814c20..7bc0141b058 100644 --- a/usr.bin/tmux/client.c +++ b/usr.bin/tmux/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.30 2009/11/04 20:50:11 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.31 2009/11/04 22:57:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -41,6 +41,7 @@ const char *client_exitmsg; void client_send_identify(int); void client_send_environ(void); void client_write_server(enum msgtype, void *, size_t); +void client_update_event(void); void client_signal(int, short, void *); void client_callback(int, short, void *); int client_dispatch(void); @@ -154,12 +155,24 @@ client_write_server(enum msgtype type, void *buf, size_t len) imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len); } +void +client_update_event(void) +{ + short events; + + event_del(&client_event); + events = EV_READ; + if (client_ibuf.w.queued > 0) + events |= EV_WRITE; + event_set(&client_event, client_ibuf.fd, events, client_callback, NULL); + event_add(&client_event, NULL); +} + __dead void client_main(void) { struct event ev_sigcont, ev_sigterm, ev_sigwinch; struct sigaction sigact; - short events; logfile("client"); @@ -197,13 +210,8 @@ client_main(void) if (client_dispatch() != 0) goto out; - /* Set up the client-server socket event. */ - events = EV_READ; - if (client_ibuf.w.queued > 0) - events |= EV_WRITE; - event_set(&client_event, client_ibuf.fd, events, client_callback, NULL); - event_add(&client_event, NULL); - + /* Set the event and dispatch. */ + client_update_event(); event_dispatch(); out: @@ -217,7 +225,7 @@ out: } void -client_signal(int sig, short events, unused void *data) +client_signal(int sig, unused short events, unused void *data) { struct sigaction sigact; @@ -240,12 +248,7 @@ client_signal(int sig, short events, unused void *data) break; } - event_del(&client_event); - events = EV_READ; - if (client_ibuf.w.queued > 0) - events |= EV_WRITE; - event_set(&client_event, client_ibuf.fd, events, client_callback, NULL); - event_add(&client_event, NULL); + client_update_event(); } void @@ -267,13 +270,7 @@ client_callback(unused int fd, short events, unused void *data) goto lost_server; } - event_del(&client_event); - events = EV_READ; - if (client_ibuf.w.queued > 0) - events |= EV_WRITE; - event_set(&client_event, client_ibuf.fd, events, client_callback, NULL); - event_add(&client_event, NULL); - + client_update_event(); return; lost_server: |