forked from EQEmu/Server
-
Notifications
You must be signed in to change notification settings - Fork 2
/
eq_stream_factory.h
61 lines (44 loc) · 1.5 KB
/
eq_stream_factory.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
#ifndef _EQSTREAMFACTORY_H
#define _EQSTREAMFACTORY_H
#include <memory>
#include <queue>
#include <map>
#include "../common/eq_stream.h"
#include "../common/condition.h"
#include "../common/timeoutmgr.h"
class EQStream;
class Timer;
class EQStreamFactory : private Timeoutable {
private:
int sock;
int Port;
bool ReaderRunning;
Mutex MReaderRunning;
bool WriterRunning;
Mutex MWriterRunning;
Condition WriterWork;
EQStreamType StreamType;
std::queue<std::shared_ptr<EQStream>> NewStreams;
Mutex MNewStreams;
std::map<std::pair<uint32, uint16>, std::shared_ptr<EQStream>> Streams;
Mutex MStreams;
virtual void CheckTimeout();
Timer *DecayTimer;
uint32 stream_timeout;
public:
EQStreamFactory(EQStreamType type, uint32 timeout = 135000) : Timeoutable(5000), stream_timeout(timeout) { ReaderRunning=false; WriterRunning=false; StreamType=type; sock=-1; }
EQStreamFactory(EQStreamType type, int port, uint32 timeout = 135000);
std::shared_ptr<EQStream> Pop();
void Push(std::shared_ptr<EQStream> s);
bool Open();
bool Open(unsigned long port) { Port=port; return Open(); }
bool IsOpen() { return sock!=-1; }
void Close();
void ReaderLoop();
void WriterLoop();
void Stop() { StopReader(); StopWriter(); }
void StopReader() { MReaderRunning.lock(); ReaderRunning=false; MReaderRunning.unlock(); }
void StopWriter() { MWriterRunning.lock(); WriterRunning=false; MWriterRunning.unlock(); WriterWork.Signal(); }
void SignalWriter() { WriterWork.Signal(); }
};
#endif