File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,11 +22,11 @@ find_package(ixwebsocket REQUIRED) # ixwebsocket https://github.com/machinezone/
2222add_executable (${EXE_NAME} main.cpp )
2323
2424target_link_libraries (${EXE_NAME} PRIVATE
25- spdlog::spdlog
26- nlohmann_json::nlohmann_json
27- CURL::libcurl
28- Threads::Threads
29- ixwebsocket::ixwebsocket
25+ Threads::Threads
26+ CURL::libcurl
27+ spdlog::spdlog
28+ nlohmann_json::nlohmann_json
29+ ixwebsocket::ixwebsocket
3030)
3131
3232if (WIN32 )
Original file line number Diff line number Diff line change 11#pragma once
22
3- #include < curl/curl.h> // libcurl global init and cleanup functions
4-
53#include < atomic>
64#include < stdexcept>
75
6+ #include < curl/curl.h> // libcurl global init and cleanup functions
7+
88// CurlGlobal : RAII wrapper for curl_global_init and curl_global_cleanup
99//
1010// Example usage:
1111// std::unique_ptr<j2::network::CurlGlobal> curlInit = nullptr;
1212// try {
1313// curlInit = std::make_unique<j2::network::CurlGlobal>();
14- // // CurlGlobal will automatically clean up when going out of scope at the end of main
1514// } catch (const std::exception& ex) {
1615// console->critical("[Fatal] CurlGlobal initialization failed: {}", ex.what());
1716// return 1;
Original file line number Diff line number Diff line change 11#pragma once
22
33#ifdef _WIN32
4+
45#include < winsock2.h>
56#include < ws2tcpip.h>
67#include < stdexcept>
78#include < string>
89
910// Windows requires WSAStartup before using sockets, and WSACleanup on shutdown.
1011// This helper struct ensures that happens.
11- namespace j2 {
12- namespace network {
12+ namespace j2 ::network {
1313
14+ // WinSockInit : RAII wrapper for WSAStartup and WSACleanup
15+ //
16+ // Example usage:
17+ // #ifdef _WIN32
18+ // try {
19+ // j2::network::WinSockInit wsi;
20+ // } catch (const std::exception& ex) {
21+ // std::cerr << "[Fatal] WinSock initialization failed: " << ex.what() << std::endl;
22+ // return 1;
23+ // }
24+ // #endif
25+ //
1426struct WinSockInit {
1527 WinSockInit () {
1628 WSADATA wsaData;
@@ -26,6 +38,5 @@ struct WinSockInit {
2638};
2739
2840} // namespace network
29- } // namespace j2
3041
31- #endif
42+ #endif // _WIN32
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ int main() {
3838 if (console == nullptr ) {
3939 std::cerr << " [Fatal] Failed to create console logger" << std::endl;
4040 return 1 ;
41- }
41+ }
4242 spdlog::set_level (spdlog::level::trace);
4343 // console->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] %v");
4444 // console->set_pattern("[%H:%M:%S.%e] [%^%l%$] %v");
@@ -51,10 +51,10 @@ int main() {
5151 } catch (const std::exception& ex) {
5252 console->critical (" [Fatal] WinSock initialization failed: {}" , ex.what ());
5353 return 1 ;
54- }
54+ }
5555#endif
5656
57- // Initialize libcurl globally; RAII wrapper ensures cleanup on exit
57+ // Initialize libcurl globally; RAII wrapper ensures cleanup on exit
5858 std::unique_ptr<j2::network::CurlGlobal> curlInit = nullptr ;
5959 try {
6060 curlInit = std::make_unique<j2::network::CurlGlobal>();
You can’t perform that action at this time.
0 commit comments