mirror of
https://github.com/CrowCpp/Crow.git
synced 2026-01-18 16:31:17 +01:00
add example for unix socket
This commit is contained in:
@@ -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)
|
||||
|
||||
27
examples/example_unix_socket.cpp
Normal file
27
examples/example_unix_socket.cpp
Normal 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();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user