.dll .so 복사 자동화 완료
This commit is contained in:
@@ -46,6 +46,14 @@ target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_lib)
|
||||
if(WIN32)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
||||
endif()
|
||||
if(UNIX AND NOT APPLE AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
BUILD_WITH_INSTALL_RPATH TRUE
|
||||
INSTALL_RPATH "$ORIGIN"
|
||||
SKIP_BUILD_RPATH FALSE
|
||||
BUILD_RPATH "$ORIGIN"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../include
|
||||
@@ -55,17 +63,27 @@ target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
|
||||
|
||||
target_precompile_headers(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include/precomp.hpp")
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE:spdlog>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying spdlog DLL to output directory"
|
||||
COMMENT "Copying spdlog DLL/so to output directory"
|
||||
)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE:jsoncpp_lib>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying jsoncpp DLL to output directory"
|
||||
COMMENT "Copying jsoncpp DLL/so to output directory"
|
||||
)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"$<TARGET_FILE_DIR:spdlog>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying spdlog library files and symlinks to output directory"
|
||||
)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"$<TARGET_FILE_DIR:jsoncpp_lib>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying jsoncpp library files and symlinks to output directory"
|
||||
)
|
||||
endif()
|
||||
@@ -5,10 +5,12 @@
|
||||
|
||||
int main() {
|
||||
Chattr::TCPSocket sock;
|
||||
sock.init(AF_INET6);
|
||||
sock.init(AF_INET);
|
||||
|
||||
Chattr::Address serveraddr(AF_INET6, "::1", 9010);
|
||||
Chattr::Address serveraddr(AF_INET, "localhost", 9011);
|
||||
|
||||
sock.connect(serveraddr);
|
||||
spdlog::info("Connection established from {}, {}", sock, (std::string)serveraddr);
|
||||
sock.send("Hello, World!", 14, 0);
|
||||
sleep(100);
|
||||
}
|
||||
@@ -47,6 +47,14 @@ target_link_libraries(${PROJECT_NAME} PRIVATE jsoncpp_lib)
|
||||
if(WIN32)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
|
||||
endif()
|
||||
if(UNIX AND NOT APPLE AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
BUILD_WITH_INSTALL_RPATH TRUE
|
||||
INSTALL_RPATH "$ORIGIN"
|
||||
SKIP_BUILD_RPATH FALSE
|
||||
BUILD_RPATH "$ORIGIN"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../include
|
||||
@@ -56,17 +64,27 @@ target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
|
||||
|
||||
target_precompile_headers(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include/precomp.hpp")
|
||||
|
||||
if(WIN32)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE:spdlog>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying spdlog DLL to output directory"
|
||||
COMMENT "Copying spdlog DLL/so to output directory"
|
||||
)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"$<TARGET_FILE:jsoncpp_lib>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying jsoncpp DLL to output directory"
|
||||
COMMENT "Copying jsoncpp DLL/so to output directory"
|
||||
)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"$<TARGET_FILE_DIR:spdlog>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying spdlog library files and symlinks to output directory"
|
||||
)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"$<TARGET_FILE_DIR:jsoncpp_lib>"
|
||||
"$<TARGET_FILE_DIR:${PROJECT_NAME}>"
|
||||
COMMENT "Copying jsoncpp library files and symlinks to output directory"
|
||||
)
|
||||
endif()
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Utils/ConfigManager.hpp"
|
||||
#include "Utils/Thread.hpp"
|
||||
#include "Utils/StringTokenizer.hpp"
|
||||
#include "Session/Session.hpp"
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
@@ -31,16 +32,33 @@ int main() {
|
||||
sock.bind(&serveraddr.addr, serveraddr.length);
|
||||
sock.listen(SOMAXCONN);
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD pid = GetCurrentProcessPid();
|
||||
#elif __linux__
|
||||
pid_t pid = getpid();
|
||||
#endif
|
||||
spdlog::info("PID : {}", pid);
|
||||
|
||||
while (true) {
|
||||
spdlog::info("Waiting for connection...");
|
||||
sock.accept(clientSock, clientAddr);
|
||||
|
||||
Chattr::Thread thread_(_TCPClient, std::move(clientSock), clientAddr);
|
||||
thread_.deatch();
|
||||
thread_.detach();
|
||||
}
|
||||
}
|
||||
|
||||
void _TCPClient(Chattr::TCPSocket sock, Chattr::Address addr) {
|
||||
spdlog::info("Connection accepted! from: {}, {}", sock, (std::string)addr);
|
||||
Sleep(10000);
|
||||
spdlog::info("Connection accepted. [{}:{}]", sock, (std::string)addr);
|
||||
|
||||
char buf[1024];
|
||||
|
||||
while (true) {
|
||||
int redSize = sock.recv(buf, 1024, 0);
|
||||
if (redSize == 0)
|
||||
break;
|
||||
std::string recvData(buf, redSize);
|
||||
spdlog::info("Red size : {}, {}", redSize, recvData);
|
||||
}
|
||||
spdlog::info("Client disconnected. [{}:{}]", sock, (std::string)addr);
|
||||
}
|
||||
@@ -42,8 +42,7 @@ Socket::operator SOCKET() const {
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
void Socket::move(const SOCKET __sock)
|
||||
{
|
||||
void Socket::set(const SOCKET __sock) {
|
||||
if (__sock == INVALID_SOCKET)
|
||||
log::critical("socket()");
|
||||
|
||||
@@ -53,14 +52,6 @@ void Socket::move(const SOCKET __sock)
|
||||
valid_ = true;
|
||||
};
|
||||
|
||||
Socket& Socket::move() {
|
||||
std::shared_ptr<Socket> socket = std::make_shared<Socket>();
|
||||
valid_ = false;
|
||||
socket->move(sock_);
|
||||
|
||||
return *socket;
|
||||
};
|
||||
|
||||
void Socket::bind(sockaddr *__addr) {
|
||||
bind((struct sockaddr *)__addr, sizeof(sockaddr));
|
||||
}
|
||||
@@ -89,6 +80,20 @@ void Socket::bind(sockaddr_in6 *__addr, socklen_t __len) {
|
||||
bind((struct sockaddr *)__addr, __len);
|
||||
}
|
||||
|
||||
int Socket::recvfrom(void *__restrict __buf, size_t __n, int __flags, struct Address& __addr) {
|
||||
int retVal = ::recvfrom(sock_, __buf, __n, __flags, &__addr.addr, &__addr.length);
|
||||
if (retVal == SOCKET_ERROR)
|
||||
log::error("recvfrom()");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int Socket::sendto(const void *__buf, size_t __n, int __flags, struct Address __addr) {
|
||||
int retVal = ::sendto(sock_, __buf, __n, __flags, &__addr.addr, __addr.length);
|
||||
if (retVal == SOCKET_ERROR)
|
||||
log::error("sendto()");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Socket::Socket(Socket &&other_) {
|
||||
other_.valid_ = false;
|
||||
sock_ = other_.sock_;
|
||||
|
||||
@@ -16,7 +16,7 @@ void TCPSocket::listen(int __n) {
|
||||
}
|
||||
|
||||
void TCPSocket::accept(TCPSocket& newSock, Address& __addr) {
|
||||
newSock.move(::accept(sock_, &__addr.addr, &__addr.length));
|
||||
newSock.set(::accept(sock_, &__addr.addr, &__addr.length));
|
||||
if (newSock == INVALID_SOCKET)
|
||||
log::critical("accept()");
|
||||
}
|
||||
@@ -27,6 +27,18 @@ void TCPSocket::connect(Chattr::Address& serveraddr) {
|
||||
log::critical("connect()");
|
||||
}
|
||||
|
||||
int TCPSocket::recv(void *__restrict __buf, size_t __n, int __flags) {
|
||||
int retVal = ::recv(sock_, __buf, __n, __flags);
|
||||
if (retVal == SOCKET_ERROR)
|
||||
log::error("recv()");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int TCPSocket::send(const void *__buf, size_t __n, int __flags) {
|
||||
int retVal = ::send(sock_, __buf, __n, __flags);
|
||||
if (retVal == SOCKET_ERROR)
|
||||
log::error("send()");
|
||||
return retVal;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#pragma once
|
||||
#include "Utils/StringTokenizer.hpp"
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
@@ -14,7 +14,7 @@ void Thread::join() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void Thread::deatch() {
|
||||
void Thread::detach() {
|
||||
detached = true;
|
||||
}
|
||||
|
||||
|
||||
21
include/Session/Session.hpp
Normal file
21
include/Session/Session.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Socket/TCPSocket.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace Chattr {
|
||||
class Session {
|
||||
public:
|
||||
Session();
|
||||
~Session();
|
||||
|
||||
bool init();
|
||||
void destruct();
|
||||
|
||||
int send();
|
||||
int recv();
|
||||
|
||||
private:
|
||||
struct std::vector<Chattr::TCPSocket> tcpSock_;
|
||||
struct std::vector<Chattr::Socket> udpSock_;
|
||||
};
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace Chattr {
|
||||
class Sesson {
|
||||
public:
|
||||
Sesson();
|
||||
~Session();
|
||||
|
||||
bool init();
|
||||
void destruct();
|
||||
|
||||
int send();
|
||||
int recv();
|
||||
|
||||
private:
|
||||
struct std::vector<Chattr::TCPSocket> sock;
|
||||
struct std::vector<Chattr::Socket> sock;
|
||||
};
|
||||
}
|
||||
@@ -15,8 +15,7 @@ public:
|
||||
void destruct();
|
||||
|
||||
operator SOCKET() const;
|
||||
void move(const SOCKET);
|
||||
Socket& move();
|
||||
void set(const SOCKET);
|
||||
|
||||
void bind(sockaddr *__addr);
|
||||
void bind(sockaddr *__addr, socklen_t __len);
|
||||
@@ -29,6 +28,9 @@ public:
|
||||
void bind(sockaddr_in6 *__addr);
|
||||
void bind(sockaddr_in6 *__addr, socklen_t __len);
|
||||
|
||||
int recvfrom(void *__restrict __buf, size_t __n, int __flags, struct Address& __addr);
|
||||
int sendto(const void *__buf, size_t __n, int __flags, struct Address __addr);
|
||||
|
||||
Socket(const Socket&) = delete;
|
||||
Socket(Socket&&);
|
||||
Socket& operator=(const Socket&) = delete;
|
||||
|
||||
@@ -11,6 +11,8 @@ public:
|
||||
void listen(int __n);
|
||||
void accept(TCPSocket& newSock, Address& addr);
|
||||
void connect(Chattr::Address& serveraddr);
|
||||
int recv(void *__restrict __buf, size_t __n, int __flags);
|
||||
int send(const void *__buf, size_t __n, int __flags);
|
||||
};
|
||||
|
||||
}
|
||||
17
include/Utils/Snowflake.hpp
Normal file
17
include/Utils/Snowflake.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace Chattr {
|
||||
|
||||
struct Snowflake {
|
||||
union {
|
||||
struct {
|
||||
std::uint64_t timestamp : 42;
|
||||
std::uint64_t instance : 10;
|
||||
std::uint64_t sequence : 12;
|
||||
};
|
||||
std::uint64_t snowflake;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
~Thread();
|
||||
|
||||
void join();
|
||||
void deatch();
|
||||
void detach();
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <netinet/in.h>
|
||||
#define SOCKET int
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
#else
|
||||
#error "이 플랫폼은 지원되지 않습니다."
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user