aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/net.h
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-25 10:47:06 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-25 10:56:03 +0200
commit08ee3cab641f367b642bc29f6540de6be85226bd (patch)
tree887f517cbec643ab90c5647d76c26e7fb024b8cc /src/net.h
parentmsg: add msg_dump_unknown (diff)
downloadcimple-08ee3cab641f367b642bc29f6540de6be85226bd.tar.gz
cimple-08ee3cab641f367b642bc29f6540de6be85226bd.zip
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.
Diffstat (limited to '')
-rw-r--r--src/net.h19
1 files changed, 8 insertions, 11 deletions
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 <stdlib.h>
-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