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

This commit is contained in:
CJ van den Berg 2026-03-02 18:46:22 +00:00
parent ed91a28f5f
commit e19ff271d0
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
9 changed files with 269 additions and 0 deletions

31
test/tcp_c_api.cpp Normal file
View file

@ -0,0 +1,31 @@
#include "tests.hpp"
#include <netinet/in.h>
#include <thespian/c/tcp.h>
using namespace thespian;
// simple smoke test of tcp C API: create + destroy handles and listen on any
// port
auto tcp_c_api(thespian::context &ctx, bool &result, thespian::env_t env)
-> thespian::result {
(void)ctx;
(void)env;
struct thespian_tcp_acceptor_handle *a = thespian_tcp_acceptor_create("tag");
check(a != nullptr);
uint16_t port = thespian_tcp_acceptor_listen(a, in6addr_any, 0);
// port may be zero if something went wrong; ignore for smoke.
(void)port;
thespian_tcp_acceptor_close(a);
thespian_tcp_acceptor_destroy(a);
struct thespian_tcp_connector_handle *c =
thespian_tcp_connector_create("tag");
check(c != nullptr);
// don't attempt to connect, simply exercise create/destroy
thespian_tcp_connector_destroy(c);
result = true;
return ok();
}

View file

@ -112,6 +112,7 @@ extern "C" auto runtestcase(const char *name) -> int {
tests["spawn_exit"] = spawn_exit;
tests["timeout_test"] = timeout_test;
tests["unx_c_api"] = unx_c_api;
tests["tcp_c_api"] = tcp_c_api;
env_t env{};
env_t log_env{};

View file

@ -28,3 +28,4 @@ testcase perf_spawn;
testcase spawn_exit;
testcase timeout_test;
testcase unx_c_api;
testcase tcp_c_api;