summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-03-11 19:09:54 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-03-20 23:44:59 +0800
commit7950f626f9b47761864c7f27eecf77c7204e6828 (patch)
tree2f6830148bd2d546d29defa583893e4a5807d080 /src
parente702fc9cdbe9808a8cc7a60bf3c414f874d81d02 (diff)
bump: compile_commands
Diffstat (limited to 'src')
-rw-r--r--src/format.hpp6
-rw-r--r--src/session.cpp13
-rw-r--r--src/session.hpp43
3 files changed, 31 insertions, 31 deletions
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;
};