rts/src/net/inc/net.h

93 lines
1.7 KiB
C
Raw Normal View History

2022-09-20 16:53:48 +02:00
#ifndef NET_H
#define NET_H
2022-09-23 04:27:58 +02:00
#include <stdbool.h>
2022-09-20 16:53:48 +02:00
#include <stddef.h>
#include <stdint.h>
2022-09-23 04:39:29 +02:00
#ifdef __cplusplus
extern "C"
{
#endif
2022-09-20 16:53:48 +02:00
enum net_domain
{
NET_DOMAIN_IPV4,
NET_DOMAIN_SERIAL
};
union net_connect
{
struct net_connect_common
{
enum net_domain domain;
2022-09-21 18:27:58 +02:00
struct net_connect_ev
{
void (*connected)(void *arg);
void (*disconnected)(void *arg);
void *arg;
} ev;
2022-09-20 16:53:48 +02:00
} 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);
2022-09-23 04:27:58 +02:00
bool net_available(enum net_domain d);
2022-09-20 16:53:48 +02:00
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);
2022-09-23 04:39:29 +02:00
#ifdef __cplusplus
}
#endif
2022-09-20 16:53:48 +02:00
#endif /* NET_H */