-
Notifications
You must be signed in to change notification settings - Fork 4
/
kakapo.h
102 lines (85 loc) · 3.34 KB
/
kakapo.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef KAKAPO_H
#define KAKAPO_H
//---------------------------------------------------------------------------
#include <WinSock2.h>
#include <ws2ipdef.h>
#include <MSWSock.h>
#include <mstcpip.h>
#include <IPHlpApi.h>
#include <stdint.h>
//---------------------------------------------------------------------------
#pragma comment(lib, "ws2_32.lib")
//---------------------------------------------------------------------------
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
//---------------------------------------------------------------------------
#define KAKAPO_TYPE_RAW 0
#define KAKAPO_TYPE_UDP 1
// listen
#define KAKAPO_TYPE_TCP 2
// client
#define KAKAPO_TYPE_TCP0 3
// server
#define KAKAPO_TYPE_TCP1 4
#define KAKAPO_CLOSE 0
#define KAKAPO_CONNECT 1
#define KAKAPO_RECV 2
#define KAKAPO_SEND 3
#define KAKAPO_TIMEOUT 4
#define KAKAPO_ERROR_ABORT0 1
#define KAKAPO_ERROR_ABORT1 2
#define KAKAPO_ERROR_TIMEOUT 3
#define KAKAPO_ERROR_REFUSED 4
#define KAKAPO_ERROR_FAILED 5
#define KAKAPO_ERROR_ACCEPT 6
#define KAKAPO_ERROR_ACCEPTED 7
#define KAKAPO_ERROR_OVERFLOW 8
#define KAKAPO_THREAD_UDP 0
#define KAKAPO_THREAD_LISTEN 1
#define KAKAPO_THREAD_CONNECT 2
#define KAKAPO_THREAD_SERVER 3
#define KAKAPO_THREAD_CLIENT 4
//---------------------------------------------------------------------------
typedef uintptr_t kkp_fd;
//---------------------------------------------------------------------------
struct kakapo;
typedef int(*t_kakapo_procedure)(struct kakapo *, void ***, void *, kkp_fd, uint8_t, uint8_t, void *, int *, const char *, int);
//---------------------------------------------------------------------------
struct kkp_ctx
{
void *context;
kkp_fd fd;
uint8_t states;
uint8_t type;
uint8_t flags;
uint8_t reserved;
};
struct kkp_box
{
CRITICAL_SECTION cs;
void *hevent;
void *hthread;
uint16_t capacity;
uint16_t count;
struct kkp_ctx ctxs[1];
};
struct kakapo
{
struct kkp_box *boxes[5]; // udp, raw;listen;connect;tcp (server);tcp (client)
void *parameter0;
void *parameter1;
int working;
CRITICAL_SECTION cs;
t_kakapo_procedure procedure;
};
//---------------------------------------------------------------------------
int kkp_initialize(struct kakapo *pkkp, void *parameter0, void *parameter1, t_kakapo_procedure procedure);
void kkp_uninitialize(struct kakapo *pkkp);
int kkp_launch_thread(struct kakapo *pkkp, uint8_t index, uint8_t capacity);
kkp_fd kkp_udp_bind(struct kakapo *pkkp, int type, void **pointer, void *context, const void *psa, int sasize);
int kkp_sendto(kkp_fd fd, const void *psa, int sasize, const char *buffer, int length);
kkp_fd kkp_connect(struct kakapo *pkkp, void *context, const void *psa, int sasize, int sendbuffersize);
kkp_fd kkp_listen(struct kakapo *pkkp, void **pointer, void *context, const void *psa, int sasize);
int kkp_send(kkp_fd fd, const char *buffer, int length, unsigned int seconds);
//---------------------------------------------------------------------------
#endif