blob: dc7481e7e32820ce58bbd22fa2c8b12621dd9ec5 (
plain) (
blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#ifndef TRANSPORT_PRIVATE_H
#define TRANSPORT_PRIVATE_H
#include <transport.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef uint8_t transport_checksum;
union transport_packet
{
struct transport_common
{
enum transport_packet_type
{
TRANSPORT_PACKET_TYPE_CONNECT,
TRANSPORT_PACKET_TYPE_DISCONNECT,
TRANSPORT_PACKET_TYPE_ACK,
TRANSPORT_PACKET_TYPE_NACK,
TRANSPORT_PACKET_TYPE_DATA,
MAX_TRANSPORT_PACKET_TYPES
} type;
enum transport_state
{
TRANSPORT_STATE_HEADER,
TRANSPORT_STATE_LEN,
TRANSPORT_STATE_BODY,
TRANSPORT_STATE_CHECKSUM
} state;
bool done;
unsigned ttl;
} common;
struct transport_packet_data
{
struct transport_common common;
uint8_t buf[TRANSPORT_MAX_DATA_LEN];
size_t n, written;
} data;
struct transport_packet_ack
{
struct transport_common common;
transport_checksum checksum;
} ack;
};
union transport_packet *transport_packet_alloc(enum transport_packet_type t);
void transport_packet_free(union transport_packet *p);
int transport_append(struct transport_handle *h, union transport_packet *p);
int transport_pop(struct transport_handle *h);
#ifdef __cplusplus
}
#endif
#endif /* TRANSPORT_PRIVATE_H */
|