1#ifndef NET_SOCKETS_H
2#define NET_SOCKETS_H
3
4#include <net_sockets/net_sockets_types.h>
5
6void * net_alloc(size_t size);
7void net_free(void *buffer);
8
9struct net_socket {
10    uint32_t descriptor;
11    bool is_closing;
12    net_received_callback_t received;
13    net_sent_callback_t sent;
14    net_connected_callback_t connected;
15    net_accepted_callback_t accepted;
16    net_closed_callback_t closed;
17    void *user_state;
18
19    struct in_addr bound_address;
20    uint16_t bound_port;
21    struct in_addr connected_address;
22    uint16_t connected_port;
23
24    struct net_socket *prev, *next;
25};
26
27struct net_socket * net_udp_socket(void);
28struct net_socket * net_tcp_socket(void);
29void net_set_user_state(struct net_socket *socket, void *user_state);
30void net_close(struct net_socket *socket);
31
32errval_t net_bind(struct net_socket *socket, struct in_addr ip_address, uint16_t port);
33errval_t net_listen(struct net_socket *socket, uint8_t backlog);
34errval_t net_print_log(void);
35
36// data must be allocated using net_alloc, it can be freed, when on_sent is called (i.e. actually sent)
37errval_t net_send(struct net_socket *socket, void *data, size_t size);
38errval_t net_send_to(struct net_socket *socket, void *data, size_t size, struct in_addr ip_address, uint16_t port);
39
40errval_t net_connect(struct net_socket *socket, struct in_addr ip_address, uint16_t port, net_connected_callback_t cb);
41
42void net_set_on_received(struct net_socket *socket, net_received_callback_t cb);
43void net_set_on_sent(struct net_socket *socket, net_sent_callback_t cb);
44void net_set_on_accepted(struct net_socket *socket, net_accepted_callback_t cb);
45void net_set_on_closed(struct net_socket *socket, net_closed_callback_t cb);
46
47
48errval_t net_sockets_init(void);
49errval_t net_sockets_init_with_card(char* cardname);
50
51#endif
52