둘 다 동시 디버깅을 위해 push

This commit is contained in:
2025-05-03 17:58:46 +09:00
parent 4bbb6837e8
commit 6ad787eed7
11 changed files with 305 additions and 97 deletions

View File

@@ -11,14 +11,14 @@ void IOCP::registerSocket(Chattr::IOCPPASSINDATA* data) {
if (returnData == 0)
completionPort_ = returnData;
#elif __linux__
// int flags = ::fcntl(data->socket.sock, F_GETFL);
// flags |= O_NONBLOCK;
// fcntl(data->socket.sock, F_SETFL, flags);
int flags = ::fcntl(data->socket->sock, F_GETFL);
flags |= O_NONBLOCK;
fcntl(data->socket->sock, F_SETFL, flags);
struct epoll_event ev;
ev.events = EPOLLIN | EPOLLONESHOT;
ev.data.ptr = data;
int rc = epoll_ctl(epollfd_, EPOLL_CTL_ADD, data->socket.sock, &ev);
int rc = epoll_ctl(epollfd_, EPOLL_CTL_ADD, data->socket->sock, &ev);
if (rc < 0)
log::critical("epoll_ctl()");
#endif
@@ -32,7 +32,7 @@ int IOCP::recv(Chattr::IOCPPASSINDATA* data, int bufferCount) {
struct epoll_event ev;
ev.events = EPOLLIN | EPOLLONESHOT;
ev.data.ptr = data;
return ::epoll_ctl(epollfd_, EPOLL_CTL_MOD, data->socket.sock, &ev);
return ::epoll_ctl(epollfd_, EPOLL_CTL_MOD, data->socket->sock, &ev);
#endif
}
@@ -44,7 +44,7 @@ int IOCP::send(Chattr::IOCPPASSINDATA* data, int bufferCount, int __flags) {
struct epoll_event ev;
ev.events = EPOLLOUT | EPOLLONESHOT;
ev.data.ptr = data;
return ::epoll_ctl(epollfd_, EPOLL_CTL_MOD, data->socket.sock, &ev);
return ::epoll_ctl(epollfd_, EPOLL_CTL_MOD, data->socket->sock, &ev);
#endif
}

View File

@@ -67,6 +67,7 @@ int Socket::bind(Address __addr) {
}
int Socket::recvfrom(void *__restrict __buf, size_t __n, int __flags, struct Address& __addr) {
std::lock_guard<std::mutex> lock(readMutex);
int retVal = ::recvfrom(sock, (char*)__buf, __n, __flags, &__addr.addr, &__addr.length);
if (retVal == SOCKET_ERROR)
log::error("recvfrom()");
@@ -74,6 +75,7 @@ int Socket::recvfrom(void *__restrict __buf, size_t __n, int __flags, struct Add
}
int Socket::sendto(const void *__buf, size_t __n, int __flags, struct Address __addr) {
std::lock_guard<std::mutex> lock(writeMutex);
int retVal = ::sendto(sock, (char*)__buf, __n, __flags, &__addr.addr, __addr.length);
if (retVal == SOCKET_ERROR)
log::error("sendto()");

32
impl/Utils/GenerateID.cpp Normal file
View File

@@ -0,0 +1,32 @@
#include "Utils/Snowflake.hpp"
namespace Chattr {
Snowflake GenerateID() {
static struct _EPOCH {
_EPOCH() {
EPOCH = std::chrono::system_clock::now();
}
std::chrono::system_clock::time_point EPOCH;
} __EPOCH__;
static std::mutex snowflakeGenerateMutex_;
std::lock_guard<std::mutex> lock(snowflakeGenerateMutex_);
#ifdef _WIN32
DWORD tid = GetCurrentThreadId();
#elif __linux__
pthread_t tid = pthread_self();
#endif
static int sequence = 0;
Snowflake id = {};
auto timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - __EPOCH__.EPOCH);
id.timestamp = timestamp.count();
id.instance = tid;
id.sequence = sequence++;
return id;
}
};

View File

@@ -63,7 +63,7 @@ void* ThreadPool::Worker() {
#elif __linux__
pthread_t pid = pthread_self();
#endif
spdlog::debug("ThreadPool Worker : {} up", pid);
spdlog::trace("ThreadPool Worker : {} up", pid);
while (!terminate_) {
std::unique_lock<std::mutex> lock(jobQueueMutex);
jobQueueCV_.wait(lock, [this]() { return !this->jobs_.empty() || terminate_; });
@@ -78,10 +78,10 @@ void* ThreadPool::Worker() {
jobs_.pop();
lock.unlock();
spdlog::debug("ThreadPool Worker : {} Executing a job", pid);
spdlog::trace("ThreadPool Worker : {} Executing a job", pid);
job();
}
spdlog::debug("ThreadPool Worker : {} down", pid);
spdlog::trace("ThreadPool Worker : {} down", pid);
return nullptr;
}