diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-03-11 19:09:54 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-03-20 23:44:59 +0800 |
| commit | 7950f626f9b47761864c7f27eecf77c7204e6828 (patch) | |
| tree | 2f6830148bd2d546d29defa583893e4a5807d080 | |
| parent | e702fc9cdbe9808a8cc7a60bf3c414f874d81d02 (diff) | |
bump: compile_commands
| -rw-r--r-- | compile_commands.json | 57 | ||||
| -rw-r--r-- | src/format.hpp | 6 | ||||
| -rw-r--r-- | src/session.cpp | 13 | ||||
| -rw-r--r-- | src/session.hpp | 43 |
4 files changed, 31 insertions, 88 deletions
diff --git a/compile_commands.json b/compile_commands.json index b617cfc..91e23f8 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -49,44 +49,6 @@ "-fPIC", "-DDEBUG", "-o", - "src/commandHandler.o", - "src/commandHandler.cpp" - ], - "directory": "/mnt/DATA/personal/Code/projects/chat-server", - "file": "/mnt/DATA/personal/Code/projects/chat-server/src/commandHandler.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/commandHandler.o" - }, - { - "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", - "-c", - "-std=c++23", - "-g3", - "-O0", - "-Wall", - "-fno-lto", - "-fPIC", - "-DDEBUG", - "-o", - "src/commands.o", - "src/commands.cpp" - ], - "directory": "/mnt/DATA/personal/Code/projects/chat-server", - "file": "/mnt/DATA/personal/Code/projects/chat-server/src/commands.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/commands.o" - }, - { - "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", - "-c", - "-std=c++23", - "-g3", - "-O0", - "-Wall", - "-fno-lto", - "-fPIC", - "-DDEBUG", - "-o", "src/FileDescriptor.o", "src/FileDescriptor.cpp" ], @@ -106,25 +68,6 @@ "-fPIC", "-DDEBUG", "-o", - "src/inputManager.o", - "src/inputManager.cpp" - ], - "directory": "/mnt/DATA/personal/Code/projects/chat-server", - "file": "/mnt/DATA/personal/Code/projects/chat-server/src/inputManager.cpp", - "output": "/mnt/DATA/personal/Code/projects/chat-server/src/inputManager.o" - }, - { - "arguments": [ - "/usr/bin/x86_64-pc-linux-gnu-g++", - "-c", - "-std=c++23", - "-g3", - "-O0", - "-Wall", - "-fno-lto", - "-fPIC", - "-DDEBUG", - "-o", "src/main.o", "src/main.cpp" ], diff --git a/src/format.hpp b/src/format.hpp index d12ceea..df1aa40 100644 --- a/src/format.hpp +++ b/src/format.hpp @@ -31,9 +31,9 @@ inline std::string fmt(eFormatType type, std::string str) { case CHAT: prefix = "[CHAT] "; break; - case TRACE: - prefix = "[DEBUG] "; - break; + case TRACE: + prefix = "[DEBUG] "; + break; default: prefix = ""; break; diff --git a/src/session.cpp b/src/session.cpp index 64dbda1..b37d896 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -3,20 +3,21 @@ #include "log.hpp" #include "server.hpp" #include "sessionManager.hpp" +#include <arpa/inet.h> #include <cerrno> #include <cstring> #include <sys/socket.h> -#include <arpa/inet.h> -CSession::CSession() : m_addrLen(sizeof(m_addr)) { - m_sockfd = Hyprutils::OS::CFileDescriptor{accept(g_pServer->getSocket()->get(), reinterpret_cast<sockaddr *>(&m_addr), &m_addrLen)}; // if this is in the init list, it will run before m_addrLen, so it won't work :/ +CSession::CSession() + : m_addrLen(sizeof(m_addr)) { + m_sockfd = Hyprutils::OS::CFileDescriptor{accept(g_pServer->getSocket()->get(), reinterpret_cast<sockaddr *>(&m_addr), &m_addrLen)}; // if this is in the init list, it will run before m_addrLen, so it won't work :/ if (!m_sockfd.isValid()) throw std::runtime_error("session: Failed to create socket"); - inet_ntop(AF_INET, &m_addr.sin_addr, m_ip, INET_ADDRSTRLEN); - m_port = ntohs(m_addr.sin_port); - log(TRACE, "session({}): connected on port {}", m_ip, m_port); + inet_ntop(AF_INET, &m_addr.sin_addr, m_ip, INET_ADDRSTRLEN); + m_port = ntohs(m_addr.sin_port); + log(TRACE, "session({}): connected on port {}", m_ip, m_port); log(TRACE, "session: initialized"); } diff --git a/src/session.hpp b/src/session.hpp index 235870c..82eca9c 100644 --- a/src/session.hpp +++ b/src/session.hpp @@ -19,18 +19,17 @@ class CSession { }; std::string getName(); - void setSelf(std::pair<std::jthread, std::shared_ptr<CSession>> *self); + 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); + 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(); - bool isValid(); - + bool isValid(); private: enum eEventType : std::uint8_t { @@ -39,22 +38,22 @@ class CSession { }; 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(); + 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; }; |
