diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-25 10:47:06 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-25 10:56:03 +0200 |
commit | 08ee3cab641f367b642bc29f6540de6be85226bd (patch) | |
tree | 887f517cbec643ab90c5647d76c26e7fb024b8cc /src/tcp_server.h | |
parent | msg: add msg_dump_unknown (diff) | |
download | cimple-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/tcp_server.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/tcp_server.h b/src/tcp_server.h new file mode 100644 index 0000000..12a819d --- /dev/null +++ b/src/tcp_server.h @@ -0,0 +1,14 @@ +#ifndef __TCP_SERVER_H__ +#define __TCP_SERVER_H__ + +struct tcp_server { + int fd; +}; + +int tcp_server_create(struct tcp_server *, const char *port); +void tcp_server_destroy(const struct tcp_server *); + +typedef int (*tcp_server_conn_handler)(int conn_fd, void *arg); +int tcp_server_accept(const struct tcp_server *, tcp_server_conn_handler, void *arg); + +#endif |