aboutsummaryrefslogtreecommitdiff
path: root/src/net/inc
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-09-27 17:03:06 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-11-01 16:26:16 +0100
commit980858186149651df5543b6fc99a4f7db0cdd089 (patch)
treed347200b0a562d84df505097651ad0642f207fdd /src/net/inc
parent39f50e601d395bbd2d78d0147ac530b756da2fff (diff)
downloadjancity-980858186149651df5543b6fc99a4f7db0cdd089.tar.gz
WIP
Diffstat (limited to 'src/net/inc')
-rw-r--r--src/net/inc/net.h65
-rw-r--r--src/net/inc/net/serial.h4
2 files changed, 43 insertions, 26 deletions
diff --git a/src/net/inc/net.h b/src/net/inc/net.h
index bbbd4ce..47bd0f8 100644
--- a/src/net/inc/net.h
+++ b/src/net/inc/net.h
@@ -3,7 +3,6 @@
#include <stdbool.h>
#include <stddef.h>
-#include <stdint.h>
#ifdef __cplusplus
extern "C"
@@ -16,39 +15,54 @@ enum net_domain
NET_DOMAIN_SERIAL
};
+enum net_role
+{
+ NET_ROLE_SERVER,
+ NET_ROLE_CLIENT
+};
+
+typedef void *net_peer;
+
+struct net_event
+{
+ void (*connected)(net_peer p, void *arg);
+ void (*disconnected)(net_peer p, void *arg);
+ void (*received)(net_peer p, const void *buf, size_t n, void *arg);
+ void *arg;
+};
+
union net_connect
{
struct net_connect_common
{
enum net_domain domain;
-
- struct net_connect_ev
- {
- void (*connected)(void *arg);
- void (*disconnected)(void *arg);
- void *arg;
- } ev;
+ struct net_event ev;
} common;
struct net_connect_ipv4
{
struct net_connect_common common;
const char *addr;
- uint16_t port;
+ short port;
} ipv4;
struct net_connect_serial
{
struct net_connect_common common;
- const char *dev;
- unsigned long baud;
- enum
+ struct net_serial_cfg
{
- NET_PARITY_NONE,
- NET_PARITY_ODD,
- NET_PARITY_EVEN
- } parity;
+ const char *dev;
+ unsigned long baud;
+ bool hw_ctrl;
+
+ enum
+ {
+ NET_PARITY_NONE,
+ NET_PARITY_ODD,
+ NET_PARITY_EVEN
+ } parity;
+ } cfg;
} serial;
};
@@ -58,31 +72,34 @@ union net_server
{
enum net_domain domain;
unsigned max_players;
+ struct net_event ev;
} common;
struct net_server_ipv4
{
struct net_server_common common;
- uint16_t port;
+ short port;
} ipv4;
struct net_server_serial
{
struct net_server_common common;
+ struct net_serial_cfg cfg;
} serial;
};
-struct net_socket;
+struct net_host;
int net_init(void);
void net_deinit(void);
-int net_update(struct net_socket *s);
+int net_update(struct net_host *s);
bool net_available(enum net_domain d);
-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);
+struct net_host *net_server(const union net_server *srv);
+struct net_host *net_connect(const union net_connect *c);
+int net_write(struct net_host *h, net_peer p, const void *buf, size_t n);
+int net_set_event(struct net_host *h, const struct net_event *ev);
+int net_close(struct net_host *s);
+enum net_role net_role(const struct net_host *s);
const char *net_domain_str(enum net_domain d);
#ifdef __cplusplus
diff --git a/src/net/inc/net/serial.h b/src/net/inc/net/serial.h
index ee81e9f..06cbc95 100644
--- a/src/net/inc/net/serial.h
+++ b/src/net/inc/net/serial.h
@@ -1,14 +1,14 @@
#ifndef NET_SERIAL_H
#define NET_SERIAL_H
-#include <stddef.h>
+#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
-const char *const *net_serial_devices(size_t *n);
+bool net_serial_unique(void);
#ifdef __cplusplus
}