From b09122e98c0156db0da4eac6d8819f1c41ecd9e1 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 14 May 2023 18:02:25 +0200 Subject: msg: add functions for one-off communication --- src/client.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/client.c') diff --git a/src/client.c b/src/client.c index f0c0d3b..8cfb1d1 100644 --- a/src/client.c +++ b/src/client.c @@ -6,18 +6,18 @@ */ #include "client.h" +#include "compiler.h" #include "log.h" #include "msg.h" #include "net.h" #include -#include struct client { - int fd; + int dummy; }; -int client_create(struct client **_client, const struct settings *settings) +int client_create(struct client **_client) { int ret = 0; @@ -27,27 +27,17 @@ int client_create(struct client **_client, const struct settings *settings) return -1; } - ret = net_connect(settings->host, settings->port); - if (ret < 0) - goto free; - client->fd = ret; - *_client = client; return ret; - -free: - free(client); - - return ret; } void client_destroy(struct client *client) { - log_errno_if(close(client->fd), "close"); free(client); } -int client_main(const struct client *client, const char **argv) +int client_main(UNUSED const struct client *client, const struct settings *settings, + const char **argv) { struct msg *request = NULL, *response = NULL; int ret = 0; @@ -56,7 +46,7 @@ int client_main(const struct client *client, const char **argv) if (ret < 0) return ret; - ret = msg_send_and_wait(client->fd, request, &response); + ret = msg_connect_and_communicate(settings->host, settings->port, request, &response); if (ret < 0) goto free_request; -- cgit v1.3