feat: add C & Zig bindings for socket

This commit is contained in:
CJ van den Berg 2026-03-02 19:02:50 +00:00
parent e19ff271d0
commit d1cb42d53c
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
11 changed files with 209 additions and 13 deletions

View file

@ -0,0 +1,25 @@
#pragma once
// NOLINTBEGIN(modernize-use-trailing-return-type)
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
struct thespian_socket_handle;
struct thespian_socket_handle *thespian_socket_create(const char *tag, int fd);
int thespian_socket_write(struct thespian_socket_handle *, const char *data,
size_t len);
int thespian_socket_write_binary(struct thespian_socket_handle *,
const uint8_t *data, size_t len);
int thespian_socket_read(struct thespian_socket_handle *);
int thespian_socket_close(struct thespian_socket_handle *);
void thespian_socket_destroy(struct thespian_socket_handle *);
#ifdef __cplusplus
}
#endif
// NOLINTEND(modernize-use-trailing-return-type)

View file

@ -26,4 +26,12 @@ struct socket {
socket_ref ref;
};
// C++ helpers used by the C binding layer
void socket_write(socket_impl *h, std::string_view data);
void socket_write_binary(socket_impl *h, const std::vector<uint8_t> &data);
void socket_read(socket_impl *h);
void socket_close(socket_impl *h);
void destroy_socket(socket_impl *h);
} // namespace thespian