-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.h
61 lines (44 loc) · 1.49 KB
/
database.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
//
// Created by 神奇bug在哪里 on 2022/12/24.
//
#ifndef FINAL_PROJECT_DATABASE_H
#define FINAL_PROJECT_DATABASE_H
#include <deque>
#include <map>
#include <mutex>
#include "serverLog.h"
#include "threadPool.h"
#include <string>
class database : public threadPool {
private:
std::map<std::string, std::string> datas; //主要的数据存储结构
std::mutex databaseLocker;
std::mutex pipeLocker;
threadPool databaseThreadPool; //线程池
struct userInfo {
std::string userName;
int uid;
std::string Avatar;
};
std::map<int, userInfo> userInfos;
std::mutex userInfosLocker;
public:
void start(int readerFd[2], int senderFd[2]);
bool putValue(const std::string &targetKey, const std::string &targetValue);
std::string getValue(const std::string &targetKey);
bool deleteValue(const std::string &t_key);
bool saveToFile();
bool readFromFile();
[[noreturn]] void taskSync(int readerFd[2], int senderFd[2]);
void putResponse(std::string targetKey, std::string targetValue, int sockID, int senderFd[2]);
void deleteResponse(std::string targetKey, int sockID, int senderFd[2]);
void getResponse(std::string targetKey, int sockID, int senderFd[2]);
~database() {
log(warning, "Force exit!\nSaving datas now....");
databaseThreadPool.stop();
saveToFile();
}
static void sigHelder(int);
};
void pipeWrite(int fd, const void *buf, uint32_t nBytes);
#endif //FINAL_PROJECT_DATABASE_H