-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTIMServer.h
84 lines (63 loc) · 2 KB
/
TIMServer.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
#pragma once
#include "JobQueue.h"
struct SessionInfo
{
SOCKET sock;
SOCKADDR_IN sockAddr;
uint64 currentRecvTime = 0;
};
class TIMServer : public JobQueue
{
public:
TIMServer() { }
~TIMServer() { }
void Init();
void Clear();
bool Start();
void Update();
// JobQueue 사용 -> 멀티스레드 오류 방지
void PushTifdList(SOCKET sock, SOCKADDR_IN sockAddr, const StTifdData* data);
void PushTirdList(SOCKET sock, SOCKADDR_IN sockAddr, const StTirdData* data);
void PopList(SessionRef ref);
void PopPairingList(int32 pairingId, SessionRef session);
bool PushPairingList(TifdRef tifd, TirdRef tird, int32 distance);
bool ChangePairingList(TifdRef tifd, TirdRef tird);
void GetPossiblePairingList(pair<float, float> tifdLocation, vector<PossiblePairingList>& lists);
// TIFD, TIRD 연결 유지
void SendKeepAliveUpdate();
void SendKeepAlive();
StLoraInfo GetLoraInfo() { return _loraInfo; }
private:
// 세션 관리 코드
void PopTifdList(TifdRef tifd);
void PopTirdList(TirdRef tird);
void PopPairingList(int32 pairingId, TifdRef session);
void PopPairingList(int32 pairingId, TirdRef session);
private:
// 초기 접속용 네트워크 코드 (TIFD, TIRD 판별)
void Disconnect(SessionInfo* info);
void Recv(SessionInfo* info);
int32 OnRecv(SessionInfo* info, BYTE* buffer, int32 size);
void OnRecvPacket(SessionInfo* info, BYTE* buffer, int32 size);
bool Send(SOCKET sock, SendBufferRef buffer);
bool Send(SOCKET sock, BYTE* buffer, int32 size);
private:
SOCKET _listenSocket = INVALID_SOCKET;
SOCKADDR_IN _sockAddr;
private:
vector<SessionInfo> _infos;
shared_ptr<RecvBuffer> _recvBuffer;
private:
USE_LOCK;
atomic<int32> _totalSize = 0;
map<std::string, TifdRef> _tifdList;
map<std::string, TirdRef> _tirdList;
// ListId가 Key로 작동
std::map<int32, PairSessionRef> _pairingSessions;
fd_set _fds;
private:
atomic<int32> _sessionCount = 1;
atomic<int32> _pairingCount = 1;
bool _isWork = true;
StLoraInfo _loraInfo;
};