aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/net.h
blob: a8acb5795bf5c14c403b3e6cf58931fa1593ca7d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Copyright (c) 2022 Egor Tensin <Egor.Tensin@gmail.com>
 * This file is part of the "cimple" project.
 * For details, see https://github.com/egor-tensin/cimple.
 * Distributed under the MIT License.
 */

#ifndef __NET_H__
#define __NET_H__

#include <stddef.h>
#include <stdint.h>

int net_bind(const char *port);
int net_accept(int fd);
int net_connect(const char *host, const char *port);

int net_send_all(int fd, const void *, size_t);
int net_recv_all(int fd, void *, size_t);

struct buf;

int buf_create(struct buf **, const void *, uint32_t);
void buf_destroy(struct buf *);

uint32_t buf_get_size(const struct buf *);
void *buf_get_data(const struct buf *);

int buf_pack_strings(struct buf **, size_t argc, const char **argv);
int buf_unpack_strings(const struct buf *, size_t *argc, const char ***argv);

int net_send_buf(int fd, const struct buf *);
int net_recv_buf(int fd, struct buf **);

#endif