aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-25 11:31:34 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-25 11:33:42 +0200
commitb5980c321f83dd6cb57302becd72642b462fb68f (patch)
treeb796e855947df96d052a8ce5bcbabca967912c81 /src
parentnet: rework API (diff)
downloadcimple-b5980c321f83dd6cb57302becd72642b462fb68f.tar.gz
cimple-b5980c321f83dd6cb57302becd72642b462fb68f.zip
msg: refactoring
Diffstat (limited to '')
-rw-r--r--src/client.c2
-rw-r--r--src/msg.c18
-rw-r--r--src/msg.h11
-rw-r--r--src/server.c4
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;
diff --git a/src/msg.c b/src/msg.c
index fc0b93c..9262f70 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -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");
diff --git a/src/msg.h b/src/msg.h
index fca230e..03e5f89 100644
--- a/src/msg.h
+++ b/src/msg.h
@@ -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)