feat: add C & Zig bindings for unix acceptor and connector

This commit is contained in:
CJ van den Berg 2026-03-02 18:43:49 +00:00
parent 628e990f6e
commit ed91a28f5f
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
9 changed files with 283 additions and 0 deletions

38
include/thespian/c/unx.h Normal file
View file

@ -0,0 +1,38 @@
#pragma once
// NOLINTBEGIN(modernize-use-trailing-return-type)
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include <stdbool.h>
// UNIX-domain socket utilities (acceptors/connectors)
// mode indicates whether the path is a filesystem entry or an abstract socket.
typedef enum thespian_unx_mode {
THESPIAN_UNX_MODE_FILE = 0,
THESPIAN_UNX_MODE_ABSTRACT = 1,
} thespian_unx_mode;
struct thespian_unx_acceptor_handle;
struct thespian_unx_acceptor_handle *
thespian_unx_acceptor_create(const char *tag);
int thespian_unx_acceptor_listen(struct thespian_unx_acceptor_handle *,
const char *path, thespian_unx_mode mode);
int thespian_unx_acceptor_close(struct thespian_unx_acceptor_handle *);
void thespian_unx_acceptor_destroy(struct thespian_unx_acceptor_handle *);
struct thespian_unx_connector_handle;
struct thespian_unx_connector_handle *
thespian_unx_connector_create(const char *tag);
int thespian_unx_connector_connect(struct thespian_unx_connector_handle *,
const char *path, thespian_unx_mode mode);
int thespian_unx_connector_cancel(struct thespian_unx_connector_handle *);
void thespian_unx_connector_destroy(struct thespian_unx_connector_handle *);
#ifdef __cplusplus
}
#endif
// NOLINTEND(modernize-use-trailing-return-type)

View file

@ -23,6 +23,11 @@ struct acceptor {
acceptor_ref ref;
};
// C++ helpers used by the C binding layer
void acceptor_listen(acceptor_impl *h, std::string_view path, mode m);
void acceptor_close(acceptor_impl *h);
void destroy_acceptor(acceptor_impl *h);
struct connector_impl;
using connector_dtor = void (*)(connector_impl *);
using connector_ref = std::unique_ptr<connector_impl, connector_dtor>;
@ -39,4 +44,9 @@ struct connector {
connector_ref ref;
};
// C++ helpers for C API
void connector_connect(connector_impl *h, std::string_view path, mode m);
void connector_cancel(connector_impl *h);
void destroy_connector(connector_impl *h);
} // namespace thespian::unx