aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/client.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-22 13:40:27 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-23 21:44:04 +0200
commit1ce4acb85a3bcb953c0f9cc91d2edc855969948b (patch)
treec06abb52fef74d375c87a7bdf39e7777bbf1b3b1 /src/client.c
parentadd doc/rationale.md (diff)
downloadcimple-1ce4acb85a3bcb953c0f9cc91d2edc855969948b.tar.gz
cimple-1ce4acb85a3bcb953c0f9cc91d2edc855969948b.zip
add some code
A basic client-server app, the client sends commands as an array of strings. Hopefully I didn't mess up, and hopefully it'll be useful.
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c
new file mode 100644
index 0000000..644cb13
--- /dev/null
+++ b/src/client.c
@@ -0,0 +1,31 @@
+#include "client.h"
+#include "cmd.h"
+#include "net.h"
+
+#include <unistd.h>
+
+int client_create(struct client *client, const struct settings *settings)
+{
+ client->fd = connect_to_host(settings->host, settings->port);
+ if (client->fd < 0)
+ return client->fd;
+
+ return 0;
+}
+
+void client_destroy(const struct client *client)
+{
+ close(client->fd);
+}
+
+int client_main(const struct client *client, int argc, char *argv[])
+{
+ int result, ret = 0;
+ struct cmd cmd = {argc, argv};
+
+ ret = cmd_send_and_wait_for_result(client->fd, &cmd, &result);
+ if (ret < 0)
+ return ret;
+
+ return result;
+}