aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/client.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-05-13 08:59:43 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-05-13 11:37:46 +0200
commitf471fbdf27462b82febe4e8db8358ab3380d2a28 (patch)
tree6c41abf4e32214cd8bdb0f8a377f93b3c7c0d830 /src/client.c
parentci_queue: fix a broken getter (diff)
downloadcimple-f471fbdf27462b82febe4e8db8358ab3380d2a28.tar.gz
cimple-f471fbdf27462b82febe4e8db8358ab3380d2a28.zip
add command module to handle request-response communications
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/client.c b/src/client.c
index 739c612..14eab14 100644
--- a/src/client.c
+++ b/src/client.c
@@ -47,24 +47,31 @@ void client_destroy(struct client *client)
free(client);
}
-int client_main(const struct client *client, int argc, char *argv[])
+int client_main(const struct client *client, const char **argv)
{
- struct msg request = {argc, argv};
- struct msg response;
+ struct msg *request;
+ struct msg *response;
int ret = 0;
- ret = msg_send_and_wait(client->fd, &request, &response);
+ ret = msg_from_argv(&request, argv);
if (ret < 0)
return ret;
- if (msg_is_error(&response)) {
+ ret = msg_send_and_wait(client->fd, request, &response);
+ if (ret < 0)
+ goto free_request;
+
+ if (msg_is_error(response)) {
log_err("Server failed to process the request\n");
ret = -1;
goto free_response;
}
free_response:
- msg_free(&response);
+ msg_free(response);
+
+free_request:
+ msg_free(request);
return ret;
}