-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathgdnet_host.h
94 lines (66 loc) · 1.91 KB
/
gdnet_host.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
/* gdnet_host.h */
#ifndef GDNET_HOST_H
#define GDNET_HOST_H
#include <string.h>
#include "os/thread.h"
#include "os/mutex.h"
#include "os/os.h"
#include "reference.h"
#include "enet/enet.h"
#include "gdnet_address.h"
#include "gdnet_event.h"
#include "gdnet_message.h"
#include "gdnet_peer.h"
#include "gdnet_queue.h"
class GDNetEvent;
class GDNetPeer;
class GDNetHost : public Reference {
OBJ_TYPE(GDNetHost,Reference);
friend class GDNetPeer;
enum {
DEFAULT_EVENT_WAIT = 1,
DEFAULT_MAX_PEERS = 32,
DEFAULT_MAX_CHANNELS = 1,
};
ENetHost* _host;
volatile bool _running;
Thread* _thread;
Mutex* _accessMutex;
Mutex* _hostMutex;
int _event_wait;
int _max_peers;
int _max_channels;
int _max_bandwidth_in;
int _max_bandwidth_out;
GDNetQueue<GDNetEvent> _event_queue;
GDNetQueue<GDNetMessage> _message_queue;
void send_messages();
void poll_events();
static void thread_callback(void *instance);
void thread_start();
void thread_loop();
void thread_stop();
void acquireMutex();
void releaseMutex();
int get_peer_id(ENetPeer *peer);
GDNetEvent* new_event(const ENetEvent& enet_event);
protected:
static void _bind_methods();
public:
GDNetHost();
Ref<GDNetPeer> get_peer(unsigned id);
void set_event_wait(int wait) { _event_wait = wait; }
void set_max_peers(int max) { _max_peers = max; }
void set_max_channels(int max) { _max_channels = max; }
void set_max_bandwidth_in(int max) { _max_bandwidth_in = max; }
void set_max_bandwidth_out(int max) { _max_bandwidth_out = max; }
Error bind(Ref<GDNetAddress> addr);
void unbind();
Ref<GDNetPeer> connect(Ref<GDNetAddress> addr = NULL, int data = 0);
void broadcast_packet(const ByteArray& packet, int channel_id = 0, int type = GDNetMessage::UNSEQUENCED);
void broadcast_var(const Variant& var, int channel_id = 0, int type = GDNetMessage::UNSEQUENCED);
bool is_event_available();
int get_event_count();
Ref<GDNetEvent> get_event();
};
#endif