aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/net.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-11-15 13:50:15 +0100
committerEgor Tensin <Egor.Tensin@gmail.com>2023-11-15 14:03:11 +0100
commit992ac5301fc8727d83017b242af2df9895eebfcc (patch)
tree4fdd21a61b54d368540d6ef65258f97473051381 /src/net.c
parentclient: print the server response (diff)
downloadcimple-992ac5301fc8727d83017b242af2df9895eebfcc.tar.gz
cimple-992ac5301fc8727d83017b242af2df9895eebfcc.zip
implement a command to list runs
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c45
1 files changed, 3 insertions, 42 deletions
diff --git a/src/net.c b/src/net.c
index cb85356..20460d9 100644
--- a/src/net.c
+++ b/src/net.c
@@ -6,6 +6,7 @@
*/
#include "net.h"
+#include "buf.h"
#include "file.h"
#include "log.h"
@@ -208,56 +209,16 @@ int net_recv(int fd, void *buf, size_t size)
return 0;
}
-struct buf {
- uint32_t size;
- const void *data;
-};
-
-int buf_create(struct buf **_buf, const void *data, uint32_t size)
-{
- struct buf *buf = malloc(sizeof(struct buf));
- if (!buf) {
- log_errno("malloc");
- return -1;
- }
-
- buf->data = data;
- buf->size = size;
-
- *_buf = buf;
- return 0;
-}
-
-int buf_create_from_string(struct buf **buf, const char *str)
-{
- return buf_create(buf, str, strlen(str) + 1);
-}
-
-void buf_destroy(struct buf *buf)
-{
- free(buf);
-}
-
-uint32_t buf_get_size(const struct buf *buf)
-{
- return buf->size;
-}
-
-const void *buf_get_data(const struct buf *buf)
-{
- return buf->data;
-}
-
int net_send_buf(int fd, const struct buf *buf)
{
int ret = 0;
- uint32_t size = htonl(buf->size);
+ uint32_t size = htonl(buf_get_size(buf));
ret = net_send(fd, &size, sizeof(size));
if (ret < 0)
return ret;
- ret = net_send(fd, buf->data, buf->size);
+ ret = net_send(fd, buf_get_data(buf), buf_get_size(buf));
if (ret < 0)
return ret;