22 #pragma comment(lib, "ws2_32.lib")
25 #include <arpa/inet.h>
30#define RETAIN_SHARED_PTR(ptr) smartptr::retain(ptr)
33#define RELEASE_SHARED_PTR(ptr) smartptr::release(ptr)
49 char ip[INET_ADDRSTRLEN];
62 WSAStartup(MAKEWORD(2, 2), &wsaData);
66 if (gethostname(hostname,
sizeof(hostname)) != 0) {
67 perror(
"gethostname failed");
68 std::exit(EXIT_FAILURE);
71 struct addrinfo hints{}, *res;
72 hints.ai_family = AF_INET;
73 hints.ai_socktype = SOCK_STREAM;
74 hints.ai_flags = AI_PASSIVE;
76 if (getaddrinfo(hostname,
nullptr, &hints, &res) != 0) {
77 perror(
"getaddrinfo failed");
78 std::exit(EXIT_FAILURE);
81 auto* ipv4 = (
struct sockaddr_in*)res->ai_addr;
82 inet_ntop(AF_INET, &(ipv4->sin_addr), net_info.ip, INET_ADDRSTRLEN);
83 net_info.family = res->ai_family;
112 sp.
ptr = std::malloc(size);
113 sp.
ref_count = (
int*)std::malloc(
sizeof(
int));
115 sp.
mutex =
new std::mutex();
165 up.
ptr = std::malloc(size);
void retain(SharedPtr *sp)
SharedPtr의 참조 카운트를 증가시킵니다.
Definition smartptr.hpp:124
void default_deleter(void *ptr)
기본 메모리 해제 함수.
Definition smartptr.hpp:41
void destroy(UniquePtr *up)
UniquePtr이 가리키는 메모리를 해제합니다.
Definition smartptr.hpp:174
SharedPtr create(size_t size, void(*deleter)(void *)=default_deleter)
SharedPtr을 생성합니다.
Definition smartptr.hpp:110
UniquePtr make_unique(size_t size, void(*deleter)(void *)=default_deleter)
UniquePtr을 생성합니다.
Definition smartptr.hpp:163
NetworkInfo get_local_network_info()
로컬 시스템의 IPv4 네트워크 정보를 가져옵니다.
Definition smartptr.hpp:57
void release(SharedPtr *sp)
SharedPtr의 참조 카운트를 감소시키고, 필요 시 메모리를 해제합니다.
Definition smartptr.hpp:134
UniquePtr transfer(UniquePtr *up)
UniquePtr의 소유권을 다른 UniquePtr로 이전합니다.
Definition smartptr.hpp:186
네트워크 정보 구조체 (IPv4 전용).
Definition smartptr.hpp:48
char ip[INET_ADDRSTRLEN]
IP 주소 (문자열)
Definition smartptr.hpp:49
int family
주소 패밀리 (AF_INET 등)
Definition smartptr.hpp:50
수동 참조 카운트를 가지는 Smart Shared Pointer 구조체.
Definition smartptr.hpp:97
int * ref_count
참조 카운트 포인터
Definition smartptr.hpp:99
void(* deleter)(void *)=default_deleter
메모리 해제 함수
Definition smartptr.hpp:101
void * ptr
실제 데이터 포인터
Definition smartptr.hpp:98
std::mutex * mutex
참조 카운트 보호용 뮤텍스
Definition smartptr.hpp:100
고유 소유권을 가지는 Unique Pointer 구조체.
Definition smartptr.hpp:152
void(* deleter)(void *)=default_deleter
메모리 해제 함수
Definition smartptr.hpp:154
void * ptr
실제 데이터 포인터
Definition smartptr.hpp:153