From e702fc9cdbe9808a8cc7a60bf3c414f874d81d02 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 11 Mar 2025 19:09:47 +0800 Subject: session: get/use IP and port on connect --- src/session.hpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/session.hpp') diff --git a/src/session.hpp b/src/session.hpp index 9133176..235870c 100644 --- a/src/session.hpp +++ b/src/session.hpp @@ -3,12 +3,13 @@ #include "FileDescriptor.hpp" #include "format.hpp" #include +#include #include #include class CSession { public: - CSession(Hyprutils::OS::CFileDescriptor m_sockfd); + CSession(); ~CSession(); struct SRecvData { @@ -18,30 +19,42 @@ class CSession { }; std::string getName(); - bool isValid(); + void setSelf(std::pair> *self); + SRecvData read(); SRecvData read(const std::string &msg); bool write(const std::string &msg, eFormatType type); template bool write(eFormatType type, std::format_string fmt, Args &&...args); + void run(); - void setSelf(std::pair> *self); + + bool isValid(); + private: - std::pair> *self; 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; + 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; }; -- cgit v1.2.3