Files
ECAP_Server/module/Local_Server/server/WebSocket_Manager.h
T
2026-07-06 09:30:04 +08:00

38 lines
1.0 KiB
C++

#pragma once
#include <string_view>
#include "Core/Base/global_include.h"
#include "Core/socket/ByteOrder.h"
#include <drogon/WebSocketConnection.h>
#include <drogon/WebSocketController.h>
class WebSocket_Manager {
public:
explicit WebSocket_Manager(std::string_view path);
~WebSocket_Manager() = default;
void remove(const drogon::WebSocketConnectionPtr &conn);
void add(const drogon::WebSocketConnectionPtr &conn);
void visit(const std::function<void(const drogon::WebSocketConnectionPtr &conn)> &func);
void push_data(const char *buf, uint64_t len);
size_t get_websocket_connect_num();
std::string path;
protected:
std::mutex mtx;
std::unordered_set<drogon::WebSocketConnectionPtr> connections;
};
class Ws_Mgr : public Psc::Singleton<Ws_Mgr> {
public:
std::shared_ptr<WebSocket_Manager> register_ws(std::string_view path);
std::shared_ptr<WebSocket_Manager> get_ws(std::string_view path);
std::map<std::string, std::shared_ptr<WebSocket_Manager>> map;
};