add example for unix socket

This commit is contained in:
na-trium-144
2024-04-20 22:50:20 +09:00
parent d962b01dec
commit 76f8c587c7
2 changed files with 31 additions and 0 deletions

View File

@@ -93,6 +93,10 @@ add_executable(example_file_upload example_file_upload.cpp)
add_warnings_optimizations(example_file_upload)
target_link_libraries(example_file_upload PUBLIC Crow::Crow)
add_executable(example_unix_socket example_unix_socket.cpp)
add_warnings_optimizations(example_unix_socket)
target_link_libraries(example_unix_socket PUBLIC Crow::Crow)
if(MSVC)
add_executable(example_vs example_vs.cpp)
add_warnings_optimizations(example_vs)

View File

@@ -0,0 +1,27 @@
#include "crow.h"
#ifdef WIN32
#include <fileapi.h>
#else
#include <unistd.h>
#include <sys/stat.h>
#endif
int main()
{
crow::SimpleApp app;
CROW_ROUTE(app, "/")
([]() {
return "Hello, world!";
});
std::string unix_path = "example.sock";
#ifdef WIN32
DeleteFileA(unix_path.c_str());
#else
unlink(unix_path.c_str());
#endif
app.unix_path(unix_path).run();
}