This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vgm_threads.h
109 lines (85 loc) · 1.72 KB
/
vgm_threads.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
103
104
105
106
107
108
109
#pragma once
#pragma warning (disable: 4512)
#include "vgm_engine.h"
#include "vgm_net.h"
#include "engine.h"
#include "scripts.h"
#include "renegade.h"
#include "vgm_asm.h"
class HostnameFetcher;
extern std::vector<HostnameFetcher *> Resolvers;
class CriticalSection {
protected:
CRITICAL_SECTION handle;
public:
CriticalSection();
CriticalSection(CRITICAL_SECTION& _handle);
~CriticalSection();
void enter();
void leave();
};
class CriticalSectionEntry {
protected:
CriticalSection& criticalSection;
public:
CriticalSectionEntry(CriticalSection& _criticalSection);
~CriticalSectionEntry();
};
class Event {
protected:
HANDLE handle;
public:
Event(bool initialState = false, bool manualReset = false);
void wait(int timeout = INFINITE);
void set();
void reset();
void pulse();
};
class Task {
public:
virtual ~Task() {};
virtual void perform() = 0;
};
class TaskList {
protected:
list<Task*> tasks;
CriticalSection lock;
Event hasPendingTasks;
bool isRunning;
void execute();
public:
TaskList();
~TaskList();
void add(Task& task);
void start();
void stop();
};
class Thread {
protected:
HANDLE handle;
int id;
bool isRunning;
static int __cdecl ThreadMain(LPVOID parameter);
virtual void execute() = 0;
public:
Thread();
~Thread();
virtual void start();
virtual void stop();
virtual bool wait(int timeout = INFINITE);
};
class HostnameFetcher : public Thread {
public:
HostnameFetcher();
~HostnameFetcher();
in_addr ip;
sockaddr_in Buffer;
char host[NI_MAXHOST];
int Resolved;
vConnectionClass *HostConnection;
virtual void execute() {
Buffer.sin_family = AF_INET;
Buffer.sin_addr = ip;
Resolved = getnameinfo((sockaddr *)&Buffer,sizeof(sockaddr_in),host,NI_MAXHOST,NULL,0,0);
};
};