tcp/udp 추가, todo:iocp openssl 지원하도록 업데이트하기

This commit is contained in:
2025-05-27 21:52:21 +09:00
parent 27f1e63c98
commit 466a80f02b
25 changed files with 1056 additions and 6 deletions

View File

@@ -1,42 +0,0 @@
#pragma once
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <glm/glm.hpp>
#include <gsl/gsl>
#include <optional>
#include <string>
#include <string_view>
#include <chrono>
#include <limits>
#include "spdlog/spdlog.h"
#include "utilities.h"
#ifdef _WIN32
#define NOMINMAX
#include <winsock2.h>
#include <ws2tcpip.h>
#include <ws2bth.h>
#include <ws2def.h>
#include <windows.h>
#define in_addr_t ULONG
#elif __linux__
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <errno.h>
#include <netinet/in.h>
#include <sys/eventfd.h>
#define SOCKET int
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#else
#error "이 플랫폼은 지원되지 않습니다."
#endif
#define MAX_BUFFERED_FRAMES (2)

View File

@@ -1,78 +0,0 @@
#pragma once
#include <condition_variable>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <queue>
#include <vector>
#include <thread>
namespace utils {
class ThreadPool {
public:
ThreadPool();
ThreadPool(std::uint32_t numThreads);
~ThreadPool();
void init(std::uint32_t numThreads);
void terminate();
void respawnWorker(std::uint32_t numThreads);
template <typename _Callable, typename... _Args>
requires(
!std::is_void_v<std::invoke_result_t<_Callable, ThreadPool*, _Args...>>)
int enqueueJob(_Callable&& __job,
std::invoke_result_t<_Callable, _Args...>& retVal,
_Args&&... __args) {
if (terminate_) {
spdlog::error("Cannot run jobs on threads that terminating...");
return -1;
}
std::lock_guard<std::mutex> lock(jobQueueMutex);
auto boundFunc = [this, &retVal, __job,
... __args = std::move(__args)]() mutable {
retVal = __job(this, std::move(__args)...);
};
auto task = std::packaged_task<void()>(std::move(boundFunc));
jobs_.push(std::move(task));
jobQueueCV_.notify_one();
return 0;
}
template <typename _Callable, typename... _Args>
requires std::is_void_v<
std::invoke_result_t<_Callable, ThreadPool*, _Args...>>
int enqueueJob(_Callable&& __job, _Args&&... __args) {
if (terminate_) {
spdlog::error("Cannot run jobs on threads that terminating...");
return -1;
}
std::lock_guard<std::mutex> lock(jobQueueMutex);
auto boundFunc = [this, __job, ... __args = std::move(__args)]() mutable {
__job(this, std::move(__args)...);
};
auto task = std::packaged_task<void()>(std::move(boundFunc));
jobs_.push(std::move(task));
jobQueueCV_.notify_one();
return 0;
}
int threadCount = 0;
private:
void* Worker();
std::condition_variable jobQueueCV_;
std::mutex jobQueueMutex;
std::queue<std::packaged_task<void()>> jobs_;
std::vector<std::thread> workers_;
bool terminate_ = false;
};
} // namespace Chattr