Fixed #35
This commit is contained in:
parent
38bbe4ec4c
commit
95b22a980a
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#define SERVER_CERT_FILE "./cert.pem"
|
#define SERVER_CERT_FILE "./cert.pem"
|
||||||
#define SERVER_PRIVATE_KEY_FILE "./key.pem"
|
#define SERVER_PRIVATE_KEY_FILE "./key.pem"
|
||||||
@ -77,7 +78,13 @@ int main(void)
|
|||||||
});
|
});
|
||||||
|
|
||||||
svr.get("/hi", [](const auto& /*req*/, auto& res) {
|
svr.get("/hi", [](const auto& /*req*/, auto& res) {
|
||||||
res.set_content("Hello World!", "text/plain");
|
res.set_content("Hello World!\n", "text/plain");
|
||||||
|
});
|
||||||
|
|
||||||
|
svr.get("/slow", [](const auto& /*req*/, auto& res) {
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(2s);
|
||||||
|
res.set_content("Slow...\n", "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.get("/dump", [](const auto& req, auto& res) {
|
svr.get("/dump", [](const auto& req, auto& res) {
|
||||||
|
@ -55,6 +55,7 @@ typedef int socket_t;
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
@ -1236,7 +1237,13 @@ inline bool Server::listen(const char* host, int port, int socket_flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: should be async
|
// TODO: should be async
|
||||||
|
#ifdef CPPHTTPLIB_NO_MULTI_THREAD_SUPPORT
|
||||||
read_and_close_socket(sock);
|
read_and_close_socket(sock);
|
||||||
|
#else
|
||||||
|
std::thread([=]() {
|
||||||
|
read_and_close_socket(sock);
|
||||||
|
}).detach();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user