aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/msg.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-06-11 12:47:21 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-06-11 12:58:07 +0200
commit04547fe158fe05f97ccf584332319da3e6b344d8 (patch)
tree904a8716d3261c53c199a967fbc651b33430db2b /src/msg.c
parentworker_queue: fix worker_queue_add_last (diff)
downloadcimple-04547fe158fe05f97ccf584332319da3e6b344d8.tar.gz
cimple-04547fe158fe05f97ccf584332319da3e6b344d8.zip
msg: rework some APIs
Diffstat (limited to 'src/msg.c')
-rw-r--r--src/msg.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/msg.c b/src/msg.c
index 0e75c75..3975a0c 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -170,7 +170,7 @@ destroy_buf:
return ret;
}
-int msg_send_from_argv(int fd, const char **argv)
+int msg_send_argv(int fd, const char **argv)
{
struct msg *msg = NULL;
int ret = 0;
@@ -224,7 +224,7 @@ destroy_buf:
return ret;
}
-int msg_communicate(int fd, const struct msg *request, struct msg **response)
+int msg_talk(int fd, const struct msg *request, struct msg **response)
{
int ret = 0;
@@ -248,8 +248,25 @@ int msg_communicate(int fd, const struct msg *request, struct msg **response)
return ret;
}
-int msg_connect_and_communicate(const char *host, const char *port, const struct msg *request,
- struct msg **response)
+int msg_talk_argv(int fd, const char **argv, struct msg **response)
+{
+ struct msg *request = NULL;
+ int ret = 0;
+
+ ret = msg_from_argv(&request, argv);
+ if (ret < 0)
+ return ret;
+
+ ret = msg_talk(fd, request, response);
+ msg_free(request);
+ if (ret < 0)
+ return ret;
+
+ return ret;
+}
+
+int msg_connect_and_talk(const char *host, const char *port, const struct msg *request,
+ struct msg **response)
{
int fd = -1, ret = 0;
@@ -257,7 +274,7 @@ int msg_connect_and_communicate(const char *host, const char *port, const struct
if (fd < 0)
return fd;
- ret = msg_communicate(fd, request, response);
+ ret = msg_talk(fd, request, response);
if (ret < 0)
goto close;
@@ -267,6 +284,24 @@ close:
return ret;
}
+int msg_connect_and_talk_argv(const char *host, const char *port, const char **argv,
+ struct msg **response)
+{
+ struct msg *request = NULL;
+ int ret = 0;
+
+ ret = msg_from_argv(&request, argv);
+ if (ret < 0)
+ return ret;
+
+ ret = msg_connect_and_talk(host, port, request, response);
+ msg_free(request);
+ if (ret < 0)
+ return ret;
+
+ return ret;
+}
+
void msg_dump(const struct msg *msg)
{
log("Message[%zu]:\n", msg->argc);