Files
dat-thang/libcess/include/cess_net.h
T
divorce b735900f2e 0.0.002
ddat interop with dat js
cable interop with cabal js
ddat's frontend = dat-thang
cable fe = cable-thang
dillo support based on cel's dillo-dat
bootstrap node
xplatform support

Signed-off-by: divo <418@cryspace.space>
2026-10-19 00:17:02 -04:00

51 lines
1.3 KiB
C

#ifndef LIBCESS_NET_H
#define LIBCESS_NET_H
#include <stddef.h>
#include <stdint.h>
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
typedef SOCKET cess_socket_t;
#define CESS_INVALID_SOCKET INVALID_SOCKET
#else
#include <sys/socket.h>
typedef int cess_socket_t;
#define CESS_INVALID_SOCKET (-1)
#endif
#define CESSNET_PORT 3282
#define CESSNET_MAX_PACKET 1400
#define CESSNET_TOPIC_BYTES 32
#define CESSNET_PEERID_BYTES 32
typedef struct cess_peer {
cess_socket_t fd;
struct sockaddr_storage addr;
socklen_t addrlen;
uint8_t id[CESSNET_PEERID_BYTES];
} cess_peer_t;
typedef struct cessnet {
cess_socket_t sock;
uint8_t topic[CESSNET_TOPIC_BYTES];
uint8_t peerid[CESSNET_PEERID_BYTES];
void *context;
void (*on_message)(struct cessnet *net, cess_peer_t *peer,
const uint8_t *msg, size_t len);
} cessnet_t;
int cessnet_init(cessnet_t *net, const uint8_t topic[CESSNET_TOPIC_BYTES],
const uint8_t peerid[CESSNET_PEERID_BYTES]);
int cessnet_bind(cessnet_t *net, const char *host, uint16_t port);
int cessnet_poll(cessnet_t *net, int timeout_ms);
int cessnet_send(cessnet_t *net, const cess_peer_t *peer,
const uint8_t *message, size_t length);
int cessnet_close(cessnet_t *net);
#endif