diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-11 19:09:47 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 23:44:59 +0800 |
| commit | e702fc9cdbe9808a8cc7a60bf3c414f874d81d02 (patch) | |
| tree | f44b7db3600671e21a9ac07cce4e7a6f6239082f /src/session.hpp | |
| parent | b3fc81f22c0f00636611ef36e70138607635c2ff (diff) | |
session: get/use IP and port on connect
Diffstat (limited to 'src/session.hpp')
| -rw-r--r-- | src/session.hpp | 21 |
1 files changed, 17 insertions, 4 deletions
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 <memory> +#include <netinet/in.h> #include <string> #include <thread> 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<std::jthread, std::shared_ptr<CSession>> *self); + SRecvData read(); SRecvData read(const std::string &msg); bool write(const std::string &msg, eFormatType type); template <typename... Args> bool write(eFormatType type, std::format_string<Args...> fmt, Args &&...args); + void run(); - void setSelf(std::pair<std::jthread, std::shared_ptr<CSession>> *self); + + bool isValid(); + private: - std::pair<std::jthread, std::shared_ptr<CSession>> *self; enum eEventType : std::uint8_t { READ, WRITE }; + + std::pair<std::jthread, std::shared_ptr<CSession>> *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; }; |
