feat: add C & Zig bindings for tcp connector and acceptor
This commit is contained in:
parent
ed91a28f5f
commit
e19ff271d0
9 changed files with 269 additions and 0 deletions
31
include/thespian/c/tcp.h
Normal file
31
include/thespian/c/tcp.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
// NOLINTBEGIN(modernize-use-trailing-return-type)
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct thespian_tcp_acceptor_handle;
|
||||
struct thespian_tcp_acceptor_handle *
|
||||
thespian_tcp_acceptor_create(const char *tag);
|
||||
uint16_t thespian_tcp_acceptor_listen(struct thespian_tcp_acceptor_handle *,
|
||||
struct in6_addr ip, uint16_t port);
|
||||
int thespian_tcp_acceptor_close(struct thespian_tcp_acceptor_handle *);
|
||||
void thespian_tcp_acceptor_destroy(struct thespian_tcp_acceptor_handle *);
|
||||
|
||||
struct thespian_tcp_connector_handle;
|
||||
struct thespian_tcp_connector_handle *
|
||||
thespian_tcp_connector_create(const char *tag);
|
||||
int thespian_tcp_connector_connect(struct thespian_tcp_connector_handle *,
|
||||
struct in6_addr ip, uint16_t port);
|
||||
int thespian_tcp_connector_cancel(struct thespian_tcp_connector_handle *);
|
||||
void thespian_tcp_connector_destroy(struct thespian_tcp_connector_handle *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
// NOLINTEND(modernize-use-trailing-return-type)
|
||||
|
|
@ -49,4 +49,15 @@ struct connector {
|
|||
connector_ref ref;
|
||||
};
|
||||
|
||||
// C++ helpers used by the C binding layer
|
||||
|
||||
auto acceptor_listen(acceptor_impl *h, const in6_addr &ip, port_t port)
|
||||
-> port_t;
|
||||
void acceptor_close(acceptor_impl *h);
|
||||
void destroy_acceptor(acceptor_impl *h);
|
||||
|
||||
void connector_connect(connector_impl *h, const in6_addr &ip, port_t port);
|
||||
void connector_cancel(connector_impl *h);
|
||||
void destroy_connector(connector_impl *h);
|
||||
|
||||
} // namespace thespian::tcp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue