blob: e2e616087b09f097e6428002cde0a546e6afd1a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#pragma once
#include "../packet/packet.h"
#include "addr.h"
#include <netinet/in.h>
typedef enum {
UDP,
TCP
} BindingType;
typedef struct {
BindingType type;
union {
UdpSocket udp;
TcpSocket tcp;
} sock;
} Binding;
void create_binding(BindingType type, uint16_t port, Binding* binding);
void free_binding(Binding* binding);
typedef struct {
BindingType type;
union {
struct {
UdpSocket udp;
SocketAddr clientaddr;
} udp;
TcpStream tcp;
} sock;
} Connection;
bool accept_connection(Binding* binding, Connection* connection);
bool read_connection(Connection* connection, Packet* packet);
bool write_connection(Connection* connection, Packet* packet);
void free_connection(Connection* connection);
bool create_request(BindingType type, SocketAddr* addr, Connection* request);
bool request_packet(Connection* request, Packet* in, Packet* out);
void free_request(Connection* connection);
|