aboutsummaryrefslogtreecommitdiff
path: root/src/net/inc
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-09-20 16:53:48 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-09-20 17:34:21 +0200
commit635d950efddde7a60edba75f7b4d5e0028e4c99a (patch)
treeaee9fce5fc800f9c86b901a7f7eb11bb27076965 /src/net/inc
parent42b976af1bb4dda02e590d604b2012cf5958c240 (diff)
downloadjancity-635d950efddde7a60edba75f7b4d5e0028e4c99a.tar.gz
Implement net component
Diffstat (limited to 'src/net/inc')
-rw-r--r--src/net/inc/net.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/net/inc/net.h b/src/net/inc/net.h
new file mode 100644
index 0000000..cdfeb0e
--- /dev/null
+++ b/src/net/inc/net.h
@@ -0,0 +1,78 @@
+#ifndef NET_H
+#define NET_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+enum net_domain
+{
+ NET_DOMAIN_IPV4,
+ NET_DOMAIN_SERIAL
+};
+
+union net_connect
+{
+ struct net_connect_common
+ {
+ enum net_domain domain;
+ void (*on_connected)(void *arg);
+ void (*on_disconnected)(void *arg);
+ void *arg;
+ } common;
+
+ struct net_connect_ipv4
+ {
+ struct net_connect_common common;
+ const char *addr;
+ uint16_t port;
+ } ipv4;
+
+ struct net_connect_serial
+ {
+ struct net_connect_common common;
+ const char *dev;
+ unsigned long baud;
+
+ enum
+ {
+ NET_PARITY_NONE,
+ NET_PARITY_ODD,
+ NET_PARITY_EVEN
+ } parity;
+ } serial;
+};
+
+union net_server
+{
+ struct net_server_common
+ {
+ enum net_domain domain;
+ unsigned max_players;
+ } common;
+
+ struct net_server_ipv4
+ {
+ struct net_server_common common;
+ uint16_t port;
+ } ipv4;
+
+ struct net_server_serial
+ {
+ struct net_server_common common;
+ } serial;
+};
+
+struct net_socket;
+
+int net_init(void);
+void net_deinit(void);
+int net_update(struct net_socket *s);
+
+struct net_socket *net_server(const union net_server *srv);
+struct net_socket *net_connect(const union net_connect *c);
+int net_read(struct net_socket *s, void *buf, size_t n);
+int net_write(struct net_socket *s, const void *buf, size_t n);
+int net_close(struct net_socket *s);
+const char *net_domain_str(enum net_domain d);
+
+#endif /* NET_H */