diff options
-rw-r--r-- | src/client.c | 2 | ||||
-rw-r--r-- | src/msg.c | 18 | ||||
-rw-r--r-- | src/msg.h | 11 | ||||
-rw-r--r-- | src/server.c | 4 |
4 files changed, 17 insertions, 18 deletions
diff --git a/src/client.c b/src/client.c index 972ebbd..e42019c 100644 --- a/src/client.c +++ b/src/client.c @@ -23,7 +23,7 @@ int client_main(const struct client *client, int argc, char *argv[]) int result, ret = 0; struct msg msg = {argc, argv}; - ret = msg_send_and_wait_for_result(client->fd, &msg, &result); + ret = msg_send_and_wait(client->fd, &msg, &result); if (ret < 0) return ret; @@ -5,6 +5,13 @@ #include <stdlib.h> #include <string.h> +void msg_free(const struct msg *msg) +{ + for (int i = 0; i < msg->argc; ++i) + free(msg->argv[i]); + free(msg->argv); +} + int msg_from_argv(struct msg *msg, const char *argv[]) { int argc = 0; @@ -114,7 +121,7 @@ free_buf: return ret; } -int msg_send_and_wait_for_result(int fd, const struct msg *msg, int *result) +int msg_send_and_wait(int fd, const struct msg *msg, int *result) { int ret = 0; @@ -162,7 +169,7 @@ free_buf: return ret; } -int msg_recv_and_send_result(int fd, msg_handler handler, void *arg) +int msg_recv_and_handle(int fd, msg_handler handler, void *arg) { struct msg msg; int result; @@ -184,13 +191,6 @@ free_msg: return ret; } -void msg_free(const struct msg *msg) -{ - for (int i = 0; i < msg->argc; ++i) - free(msg->argv[i]); - free(msg->argv); -} - int msg_dump_unknown(const struct msg *msg) { print_log("Received an unknown message:\n"); @@ -6,17 +6,16 @@ struct msg { char **argv; }; +void msg_free(const struct msg *); + int msg_from_argv(struct msg *, const char *argv[]); +int msg_recv(int fd, struct msg *); int msg_send(int fd, const struct msg *); -int msg_send_and_wait_for_result(int fd, const struct msg *, int *result); typedef int (*msg_handler)(const struct msg *, void *arg); - -int msg_recv(int fd, struct msg *); -int msg_recv_and_send_result(int fd, msg_handler, void *arg); - -void msg_free(const struct msg *); +int msg_send_and_wait(int fd, const struct msg *, int *result); +int msg_recv_and_handle(int fd, msg_handler, void *arg); int msg_dump_unknown(const struct msg *); diff --git a/src/server.c b/src/server.c index 00789d5..3e9f080 100644 --- a/src/server.c +++ b/src/server.c @@ -22,14 +22,14 @@ void server_destroy(const struct server *server) tcp_server_destroy(&server->tcp_server); } -static int msg_handle(const struct msg *msg, void *) +static int server_msg_handler(const struct msg *msg, void *) { return msg_dump_unknown(msg); } static int server_conn_handler(int fd, void *) { - return msg_recv_and_send_result(fd, msg_handle, NULL); + return msg_recv_and_handle(fd, server_msg_handler, NULL); } int server_main(const struct server *server) |