-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManagement.h
102 lines (83 loc) · 2.27 KB
/
Management.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
//
// Created by Clancy on 2021/1/26.
//
#ifndef CPP_CMD_CS_TEST_SERVER_MANAGEMENT_H
#define CPP_CMD_CS_TEST_SERVER_MANAGEMENT_H
#include <cstdio>
#include <sys/socket.h>
#include <netinet/in.h>
#include <cstdlib>
#include <arpa/inet.h>
#include <unistd.h>
#include <cstring>
#include "string"
#include <iostream>
#include <cerrno>
#include <vector>
#include <map>
using namespace std;
#define SOCKET int
#define SOCKADDR_IN sockaddr_in
#define SOCKADDR sockaddr
#define POST 1234
/* *********** 基础信息存放结构体 ************** */
// 数据信息
struct DataInfo {
uint16_t flags; // 标志位:0x01登录,0x02退出,0x03发送信息
uint16_t len; // 负载长度(小于1000)
char data[1020]; // 负载
};
// socket信息
struct SocketInfo{
SOCKET socket;
SOCKADDR_IN sockaddrIn;
};
// 客户端详情
struct ClientInfo{
uint64_t clientId;
string clientName;
string clientIp;
uint64_t connectNum;
ClientInfo(): connectNum(0){};
bool operator==(const ClientInfo& clientInfo) const{
return (clientInfo.clientId == this->clientId && clientInfo.clientName == this->clientName);
}
};
// 聊天记录
struct ChatRecord{
ClientInfo clientInfo;
string record;
bool kill_process;
ChatRecord(ClientInfo& clientInfo,const string& record,bool kill_process = false):
clientInfo(clientInfo),record(record),kill_process(kill_process){}
};
// SocketThread线程参数
struct SocketParam{
SocketInfo socketInfo;
ClientInfo clientInfo;
vector<ChatRecord> *chatRecordVector;
map<uint64_t ,ClientInfo> *clientMap;
};
// CallbackThread参数
struct CallbackParam{
uint16_t *m_stop;
SOCKET clientSocket;
vector<ChatRecord> *chatRecordVector;
CallbackParam(uint16_t* m_stop,SOCKET clientSocket,vector<ChatRecord> *chatRecordVector):
m_stop(m_stop),clientSocket(clientSocket),chatRecordVector(chatRecordVector)
{}
};
// 服务管理类,用于启动
bool Init(SocketInfo&);
class ServiceManagement {
public:
ServiceManagement();
~ServiceManagement(){
if(status_) close(receive_socket_);
}
bool status_; //激活状态
SOCKET receive_socket_;
SOCKADDR_IN receive_add_in_;
};
void * SocketThread(void *arg);
#endif //CPP_CMD_CS_TEST_SERVER_MANAGEMENT_H