From 08ee3cab641f367b642bc29f6540de6be85226bd Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 25 Aug 2022 10:47:06 +0200 Subject: net: rework API First, rename all API functions so that they start with net_. Second, abstract the basic TCP server functionality into tcp_server.c. This includes reworking net_accept so that it's a simple blocking operation, and putting the callback stuff to tcp_server.c. Also, the server now uses detached threads instead of fork(), since I want connection handlers to share memory. --- src/net.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/net.h') diff --git a/src/net.h b/src/net.h index 644520c..ce1c536 100644 --- a/src/net.h +++ b/src/net.h @@ -3,18 +3,15 @@ #include -int bind_to_port(const char *port); +int net_bind(const char *port); +int net_accept(int fd); +int net_connect(const char *host, const char *port); -typedef int (*connection_handler)(int fd, void *arg); -int accept_connection(int fd, connection_handler, void *arg); +int net_send_all(int fd, const void *, size_t); +int net_send_buf(int fd, const void *, size_t); -int connect_to_host(const char *host, const char *port); - -int send_all(int fd, const void *, size_t); -int send_buf(int fd, const void *, size_t); - -ssize_t recv_all(int fd, void *, size_t); -int recv_buf(int fd, void **, size_t *); -int recv_static(int fd, void *, size_t); +ssize_t net_recv_all(int fd, void *, size_t); +int net_recv_buf(int fd, void **, size_t *); +int net_recv_static(int fd, void *, size_t); #endif -- cgit v1.2.3