48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
//
|
|
// Created by dongl on 23-5-10.
|
|
//
|
|
|
|
#ifndef IM2_SESSION_H
|
|
#define IM2_SESSION_H
|
|
|
|
#include "event2/bufferevent.h"
|
|
#include "agreement.h"
|
|
#include <string>
|
|
#include <map>
|
|
#include <optional>
|
|
#include <oneapi/tbb/task_group.h>
|
|
#include <list>
|
|
|
|
struct userinfo {
|
|
bufferevent* bev;
|
|
char ip[15];
|
|
std::map<std::string, std::string> session; // 用户的 seesion;
|
|
};
|
|
|
|
|
|
class session {
|
|
public:
|
|
// 用户不在线时应 删除 user fd 映射
|
|
void add_user(mp::sri* sri, std::shared_ptr<agreement_request>& request);
|
|
void remove_user(const std::shared_ptr<agreement_request>& request);
|
|
void remove_user(bufferevent* bev);
|
|
bool is_user(const std::string& account);
|
|
std::optional<std::pair<uint64_t, userinfo*>> find_user_fd(uint64_t account);
|
|
|
|
void init_session(bufferevent* bev);
|
|
void set_session(bufferevent* bev, const std::string& session_key, const std::string& session_value);
|
|
std::optional<std::string> get_session(bufferevent* bev, const std::string& session_key);
|
|
void remove_session(bufferevent* bev, const std::string& session_key);
|
|
|
|
void timing();
|
|
|
|
protected:
|
|
tbb::task_group time_wheel; // 时间轮 线程池
|
|
std::map<uint64_t, userinfo*> user_fd; // 用户的链接 暂时是一直链接 交给libevent 管理
|
|
std::map<bufferevent*, std::map<std::string, std::string>> session_map; // 当前链接的 存在的 seesion;
|
|
std::map<time_t, std::list< std::pair<bufferevent*/*bev*/, std::string/*key*/> > > session_time_wheel; // session 有效期 超时轮 映射
|
|
};
|
|
|
|
|
|
#endif //IM2_SESSION_H
|