#pragma once #include "FileDescriptor.hpp" #include "format.hpp" #include #include #include #include class CSession { public: CSession(); ~CSession(); struct SRecvData { std::string data; bool good = true; }; std::string getName(); void setSelf(std::pair> *self); std::unique_ptr read(); std::unique_ptr read(const std::string &msg); bool write(const std::string &msg); template bool write(std::format_string fmt, Args &&...args); template bool write(eFormatType type, std::format_string fmt, Args &&...args); void run(); bool isValid(); private: enum eEventType : std::uint8_t { READ, WRITE }; std::pair> *self; Hyprutils::OS::CFileDescriptor m_sockfd; sockaddr_in m_addr; socklen_t m_addrLen = sizeof(m_addr); std::string m_name; char m_ip[INET_ADDRSTRLEN]; int m_port; bool m_isReading = false; void recvLoop(); bool registerSession(); void onConnect(); void onDisconnect(); void onErrno(eEventType); void onRecv(const SRecvData &data); void onSend(const std::string &msg); void onShutdown(); friend class CSessionManager; };