summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-09-26 18:09:23 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-09-26 18:09:23 +0000
commit302a35da85c223aae29b4d356787ee492c9b56d7 (patch)
tree3f9988645f29cad5e427e00bc29e4edbcaf60239
parent65eeb7e421718e248790d858792fd820aabbdbe6 (diff)
Server function naming, still not happy with server stuff though.
-rw-r--r--client-cmd.c3
-rw-r--r--client-msg.c4
-rw-r--r--server-fn.c16
-rw-r--r--server-msg.c40
-rw-r--r--server.c77
-rw-r--r--tmux.h16
6 files changed, 77 insertions, 79 deletions
diff --git a/client-cmd.c b/client-cmd.c
index 998fee2c..6749ca3a 100644
--- a/client-cmd.c
+++ b/client-cmd.c
@@ -1,4 +1,4 @@
-/* $Id: client-cmd.c,v 1.1 2007-09-26 13:43:14 nicm Exp $ */
+/* $Id: client-cmd.c,v 1.2 2007-09-26 18:09:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -62,7 +62,6 @@ struct cmd client_cmd_table[] = {
};
#define NCLIENTCMD (sizeof client_cmd_table / sizeof client_cmd_table[0])
-/* Dispatch to a command. */
int
client_cmd_dispatch(int key, struct client_ctx *cctx, const char **error)
{
diff --git a/client-msg.c b/client-msg.c
index 6639d915..29b8c7b3 100644
--- a/client-msg.c
+++ b/client-msg.c
@@ -1,4 +1,4 @@
-/* $Id: client-msg.c,v 1.1 2007-09-26 13:43:14 nicm Exp $ */
+/* $Id: client-msg.c,v 1.2 2007-09-26 18:09:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -69,7 +69,7 @@ client_msg_dispatch(struct client_ctx *cctx, const char **error)
}
}
-/* Output message from client. */
+/* Output message from server. */
int
client_msg_fn_output(
struct hdr *hdr, struct client_ctx *cctx, unused const char **error)
diff --git a/server-fn.c b/server-fn.c
index 1332d03d..668712b0 100644
--- a/server-fn.c
+++ b/server-fn.c
@@ -1,4 +1,4 @@
-/* $Id: server-fn.c,v 1.1 2007-09-26 10:35:24 nicm Exp $ */
+/* $Id: server-fn.c,v 1.2 2007-09-26 18:09:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,7 +24,7 @@
/* Write command to a client. */
void
-write_client(struct client *c, u_int cmd, void *buf, size_t len)
+server_write_client(struct client *c, u_int cmd, void *buf, size_t len)
{
struct hdr hdr;
@@ -38,7 +38,7 @@ write_client(struct client *c, u_int cmd, void *buf, size_t len)
/* Write command to a client with two buffers. */
void
-write_client2(struct client *c,
+server_write_client2(struct client *c,
u_int cmd, void *buf1, size_t len1, void *buf2, size_t len2)
{
struct hdr hdr;
@@ -55,7 +55,7 @@ write_client2(struct client *c,
/* Write command to all clients attached to a specific window. */
void
-write_clients(struct window *w, u_int cmd, void *buf, size_t len)
+server_write_clients(struct window *w, u_int cmd, void *buf, size_t len)
{
struct client *c;
struct hdr hdr;
@@ -78,19 +78,19 @@ write_clients(struct window *w, u_int cmd, void *buf, size_t len)
/* Changed client window. */
void
-changed_window(struct client *c)
+server_window_changed(struct client *c)
{
struct window *w;
w = c->session->window;
if (c->sx != w->screen.sx || c->sy != w->screen.sy)
window_resize(w, c->sx, c->sy);
- draw_client(c, 0, c->sy - 1);
+ server_draw_client(c, 0, c->sy - 1);
}
/* Draw window on client. */
void
-draw_client(struct client *c, u_int py_upper, u_int py_lower)
+server_draw_client(struct client *c, u_int py_upper, u_int py_lower)
{
struct hdr hdr;
size_t size;
@@ -115,7 +115,7 @@ draw_client(struct client *c, u_int py_upper, u_int py_lower)
/* Write message command to a client. */
void
-write_message(struct client *c, const char *fmt, ...)
+server_write_message(struct client *c, const char *fmt, ...)
{
struct hdr hdr;
va_list ap;
diff --git a/server-msg.c b/server-msg.c
index 1c0de755..1cce4481 100644
--- a/server-msg.c
+++ b/server-msg.c
@@ -1,4 +1,4 @@
-/* $Id: server-msg.c,v 1.2 2007-09-26 13:43:15 nicm Exp $ */
+/* $Id: server-msg.c,v 1.3 2007-09-26 18:09:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -114,7 +114,7 @@ server_msg_fn_new(struct hdr *hdr, struct client *c)
if (*data.name != '\0' && session_find(data.name) != NULL) {
xasprintf(&msg, "duplicate session: %s", data.name);
- write_client(c, MSG_ERROR, msg, strlen(msg));
+ server_write_client(c, MSG_ERROR, msg, strlen(msg));
xfree(msg);
return (0);
}
@@ -128,7 +128,7 @@ server_msg_fn_new(struct hdr *hdr, struct client *c)
fatalx("session_create failed");
xfree(cmd);
- draw_client(c, 0, c->sy - 1);
+ server_draw_client(c, 0, c->sy - 1);
return (0);
}
@@ -157,12 +157,12 @@ server_msg_fn_attach(struct hdr *hdr, struct client *c)
c->session = session_find(data.name);
if (c->session == NULL) {
xasprintf(&msg, "session not found: %s", data.name);
- write_client(c, MSG_ERROR, msg, strlen(msg));
+ server_write_client(c, MSG_ERROR, msg, strlen(msg));
xfree(msg);
return (0);
}
- draw_client(c, 0, c->sy - 1);
+ server_draw_client(c, 0, c->sy - 1);
return (0);
}
@@ -187,7 +187,7 @@ server_msg_fn_create(struct hdr *hdr, struct client *c)
fatalx("session_new failed");
xfree(cmd);
- draw_client(c, 0, c->sy - 1);
+ server_draw_client(c, 0, c->sy - 1);
return (0);
}
@@ -202,9 +202,9 @@ server_msg_fn_next(struct hdr *hdr, struct client *c)
fatalx("bad MSG_NEXT size");
if (session_next(c->session) == 0)
- changed_window(c);
+ server_window_changed(c);
else
- write_message(c, "No next window");
+ server_write_message(c, "No next window");
return (0);
}
@@ -219,9 +219,9 @@ server_msg_fn_previous(struct hdr *hdr, struct client *c)
fatalx("bad MSG_PREVIOUS size");
if (session_previous(c->session) == 0)
- changed_window(c);
+ server_window_changed(c);
else
- write_message(c, "No previous window");
+ server_write_message(c, "No previous window");
return (0);
}
@@ -246,7 +246,7 @@ server_msg_fn_size(struct hdr *hdr, struct client *c)
c->sy = 25;
if (window_resize(c->session->window, c->sx, c->sy) != 0)
- draw_client(c, 0, c->sy - 1);
+ server_draw_client(c, 0, c->sy - 1);
return (0);
}
@@ -274,7 +274,7 @@ server_msg_fn_refresh(struct hdr *hdr, struct client *c)
if (hdr->size != 0 && hdr->size != sizeof data)
fatalx("bad MSG_REFRESH size");
- draw_client(c, 0, c->sy - 1);
+ server_draw_client(c, 0, c->sy - 1);
return (0);
}
@@ -294,9 +294,9 @@ server_msg_fn_select(struct hdr *hdr, struct client *c)
if (c->session == NULL)
return (0);
if (session_select(c->session, data.idx) == 0)
- changed_window(c);
+ server_window_changed(c);
else
- write_message(c, "Window %u not present", data.idx);
+ server_write_message(c, "Window %u not present", data.idx);
return (0);
}
@@ -319,7 +319,7 @@ server_msg_fn_sessions(struct hdr *hdr, struct client *c)
if (ARRAY_ITEM(&sessions, i) != NULL)
data.sessions++;
}
- write_client2(c, MSG_SESSIONS,
+ server_write_client2(c, MSG_SESSIONS,
&data, sizeof data, NULL, data.sessions * sizeof entry);
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
@@ -356,7 +356,7 @@ server_msg_fn_windows(struct hdr *hdr, struct client *c)
s = session_find(data.name);
if (s == NULL) {
data.windows = 0;
- write_client(c, MSG_WINDOWS, &data, sizeof data);
+ server_write_client(c, MSG_WINDOWS, &data, sizeof data);
return (0);
}
@@ -365,7 +365,7 @@ server_msg_fn_windows(struct hdr *hdr, struct client *c)
if (ARRAY_ITEM(&windows, i) != NULL)
data.windows++;
}
- write_client2(c, MSG_WINDOWS,
+ server_write_client2(c, MSG_WINDOWS,
&data, sizeof data, NULL, data.windows * sizeof entry);
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
@@ -405,9 +405,9 @@ server_msg_fn_last(struct hdr *hdr, struct client *c)
fatalx("bad MSG_LAST size");
if (session_last(c->session) == 0)
- changed_window(c);
+ server_window_changed(c);
else
- write_message(c, "No last window");
+ server_write_message(c, "No last window");
return (0);
}
@@ -441,7 +441,7 @@ server_msg_fn_windowlist(struct hdr *hdr, struct client *c)
break;
}
- write_message(c, "%s", buf);
+ server_write_message(c, "%s", buf);
xfree(buf);
return (0);
diff --git a/server.c b/server.c
index 3c12543d..814739c3 100644
--- a/server.c
+++ b/server.c
@@ -1,4 +1,4 @@
-/* $Id: server.c,v 1.13 2007-09-26 13:43:15 nicm Exp $ */
+/* $Id: server.c,v 1.14 2007-09-26 18:09:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -45,22 +45,23 @@
struct clients clients;
int server_main(char *, int);
-void fill_windows(struct pollfd **);
-void handle_windows(struct pollfd **);
-void fill_clients(struct pollfd **);
-void handle_clients(struct pollfd **);
-struct client *accept_client(int);
-void lost_client(struct client *);
-void lost_window(struct window *);
-
+void server_fill_windows(struct pollfd **);
+void server_handle_windows(struct pollfd **);
+void server_fill_clients(struct pollfd **);
+void server_handle_clients(struct pollfd **);
+struct client *server_accept_client(int);
+void server_lost_client(struct client *);
+void server_lost_window(struct window *);
+
+/* Fork new server. */
int
server_start(char *path)
{
struct sockaddr_un sa;
size_t sz;
pid_t pid;
- mode_t mode;
- int fd;
+ mode_t mask;
+ int fd, mode;
switch (pid = fork()) {
case -1:
@@ -74,10 +75,8 @@ server_start(char *path)
logfile("server");
setproctitle("server (%s)", path);
-
log_debug("server started, pid %ld", (long) getpid());
- /* Create the socket. */
memset(&sa, 0, sizeof sa);
sa.sun_family = AF_UNIX;
sz = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
@@ -90,14 +89,19 @@ server_start(char *path)
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
fatal("socket failed");
- mode = umask(S_IXUSR|S_IRWXG|S_IRWXO);
+ mask = umask(S_IXUSR|S_IRWXG|S_IRWXO);
if (bind(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1)
fatal("bind failed");
- umask(mode);
+ umask(mask);
if (listen(fd, 16) == -1)
fatal("listen failed");
+ if ((mode = fcntl(fd, F_GETFL)) == -1)
+ fatal("fcntl failed");
+ if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
+ fatal("fcntl failed");
+
/*
* Detach into the background. This means the PID changes which will
* have to be fixed in some way at some point... XXX
@@ -113,8 +117,8 @@ server_start(char *path)
int
server_main(char *srv_path, int srv_fd)
{
- struct pollfd *pfds, *pfd;
- int nfds, mode;
+ struct pollfd *pfds, *pfd;
+ int nfds;
siginit();
@@ -122,11 +126,6 @@ server_main(char *srv_path, int srv_fd)
ARRAY_INIT(&clients);
ARRAY_INIT(&sessions);
- if ((mode = fcntl(srv_fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(srv_fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
-
pfds = NULL;
while (!sigterm) {
/* Initialise pollfd array. */
@@ -140,8 +139,8 @@ server_main(char *srv_path, int srv_fd)
pfd++;
/* Fill window and client sockets. */
- fill_windows(&pfd);
- fill_clients(&pfd);
+ server_fill_windows(&pfd);
+ server_fill_clients(&pfd);
/* Do the poll. */
if (poll(pfds, nfds, INFTIM) == -1) {
@@ -155,7 +154,7 @@ server_main(char *srv_path, int srv_fd)
if (pfd->revents & (POLLERR|POLLNVAL|POLLHUP))
fatalx("lost server socket");
if (pfd->revents & POLLIN) {
- accept_client(srv_fd);
+ server_accept_client(srv_fd);
continue;
}
pfd++;
@@ -165,8 +164,8 @@ server_main(char *srv_path, int srv_fd)
* windows, so windows must come first to avoid messing up by
* increasing the array size.
*/
- handle_windows(&pfd);
- handle_clients(&pfd);
+ server_handle_windows(&pfd);
+ server_handle_clients(&pfd);
}
close(srv_fd);
@@ -177,7 +176,7 @@ server_main(char *srv_path, int srv_fd)
/* Fill window pollfds. */
void
-fill_windows(struct pollfd **pfd)
+server_fill_windows(struct pollfd **pfd)
{
struct window *w;
u_int i;
@@ -197,7 +196,7 @@ fill_windows(struct pollfd **pfd)
/* Handle window pollfds. */
void
-handle_windows(struct pollfd **pfd)
+server_handle_windows(struct pollfd **pfd)
{
struct window *w;
u_int i;
@@ -206,12 +205,12 @@ handle_windows(struct pollfd **pfd)
for (i = 0; i < ARRAY_LENGTH(&windows); i++) {
if ((w = ARRAY_ITEM(&windows, i)) != NULL) {
if (window_poll(w, *pfd) != 0)
- lost_window(w);
+ server_lost_window(w);
else {
b = buffer_create(BUFSIZ);
window_output(w, b);
if (BUFFER_USED(b) != 0) {
- write_clients(w, MSG_OUTPUT,
+ server_write_clients(w, MSG_OUTPUT,
BUFFER_OUT(b), BUFFER_USED(b));
}
buffer_destroy(b);
@@ -223,7 +222,7 @@ handle_windows(struct pollfd **pfd)
/* Fill client pollfds. */
void
-fill_clients(struct pollfd **pfd)
+server_fill_clients(struct pollfd **pfd)
{
struct client *c;
u_int i;
@@ -243,7 +242,7 @@ fill_clients(struct pollfd **pfd)
/* Handle client pollfds. */
void
-handle_clients(struct pollfd *(*pfd))
+server_handle_clients(struct pollfd *(*pfd))
{
struct client *c;
u_int i;
@@ -251,7 +250,7 @@ handle_clients(struct pollfd *(*pfd))
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
if ((c = ARRAY_ITEM(&clients, i)) != NULL) {
if (buffer_poll((*pfd), c->in, c->out) != 0)
- lost_client(c);
+ server_lost_client(c);
else
server_msg_dispatch(c);
}
@@ -261,7 +260,7 @@ handle_clients(struct pollfd *(*pfd))
/* accept(2) and create new client. */
struct client *
-accept_client(int srv_fd)
+server_accept_client(int srv_fd)
{
struct client *c;
struct sockaddr_storage sa;
@@ -298,7 +297,7 @@ accept_client(int srv_fd)
/* Lost a client. */
void
-lost_client(struct client *c)
+server_lost_client(struct client *c)
{
u_int i;
@@ -315,7 +314,7 @@ lost_client(struct client *c)
/* Lost window: move clients on to next window. */
void
-lost_window(struct window *w)
+server_lost_window(struct window *w)
{
struct client *c;
struct session *s;
@@ -337,9 +336,9 @@ lost_window(struct window *w)
continue;
if (destroyed) {
c->session = NULL;
- write_client(c, MSG_EXIT, NULL, 0);
+ server_write_client(c, MSG_EXIT, NULL, 0);
} else
- changed_window(c);
+ server_window_changed(c);
}
}
}
diff --git a/tmux.h b/tmux.h
index c35a951f..c01d58d6 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.12 2007-09-26 13:43:15 nicm Exp $ */
+/* $Id: tmux.h,v 1.13 2007-09-26 18:09:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -462,15 +462,15 @@ int server_start(char *);
int server_msg_dispatch(struct client *);
/* server-fn.c */
-void write_message(struct client *, const char *, ...);
-void write_client(struct client *, u_int, void *, size_t);
-void write_client2(
+void server_write_message(struct client *, const char *, ...);
+void server_write_client(struct client *, u_int, void *, size_t);
+void server_write_client2(
struct client *, u_int, void *, size_t, void *, size_t);
-void write_clients(struct window *, u_int, void *, size_t);
-void changed_window(struct client *);
-void draw_client(struct client *, u_int, u_int);
+void server_write_clients(struct window *, u_int, void *, size_t);
+void server_window_changed(struct client *);
+void server_draw_client(struct client *, u_int, u_int);
-/* ansi.c */
+/* input.c */
void input_key(struct buffer *, int);
size_t input_parse(u_char *, size_t, struct buffer *, struct screen *);
uint8_t input_extract8(struct buffer *);