Move some common code into a function.

This commit is contained in:
Nicholas Marriott 2009-11-04 22:57:49 +00:00
parent fde36fccc3
commit 862fe15c32

View File

@ -41,6 +41,7 @@ const char *client_exitmsg;
void client_send_identify(int); void client_send_identify(int);
void client_send_environ(void); void client_send_environ(void);
void client_write_server(enum msgtype, void *, size_t); void client_write_server(enum msgtype, void *, size_t);
void client_update_event(void);
void client_signal(int, short, void *); void client_signal(int, short, void *);
void client_callback(int, short, void *); void client_callback(int, short, void *);
int client_dispatch(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); 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 __dead void
client_main(void) client_main(void)
{ {
struct event ev_sigcont, ev_sigterm, ev_sigwinch; struct event ev_sigcont, ev_sigterm, ev_sigwinch;
struct sigaction sigact; struct sigaction sigact;
short events;
logfile("client"); logfile("client");
@ -197,13 +210,8 @@ client_main(void)
if (client_dispatch() != 0) if (client_dispatch() != 0)
goto out; goto out;
/* Set up the client-server socket event. */ /* Set the event and dispatch. */
events = EV_READ; client_update_event();
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);
event_dispatch(); event_dispatch();
out: out:
@ -217,7 +225,7 @@ out:
} }
void void
client_signal(int sig, short events, unused void *data) client_signal(int sig, unused short events, unused void *data)
{ {
struct sigaction sigact; struct sigaction sigact;
@ -240,12 +248,7 @@ client_signal(int sig, short events, unused void *data)
break; break;
} }
event_del(&client_event); client_update_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);
} }
void void
@ -267,13 +270,7 @@ client_callback(unused int fd, short events, unused void *data)
goto lost_server; goto lost_server;
} }
event_del(&client_event); client_update_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);
return; return;
lost_server: lost_server: