|
|
|
@ -1,5 +1,7 @@
@@ -1,5 +1,7 @@
|
|
|
|
|
|
|
|
|
|
#include "util.h" |
|
|
|
|
#include <signal.h> |
|
|
|
|
#include <sys/wait.h> |
|
|
|
|
|
|
|
|
|
std::string
|
|
|
|
|
file_ext(std::string path)
|
|
|
|
@ -20,9 +22,6 @@ std::string read_file(std::string const &fpath) {
@@ -20,9 +22,6 @@ std::string read_file(std::string const &fpath) {
|
|
|
|
|
return sstr.str(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string
|
|
|
|
|
reformat_date(const std::string& date_time, const std::map<std::string, std::string> &properties)
|
|
|
|
|
{ |
|
|
|
@ -90,3 +89,39 @@ compute_url(fs::path path, std::map<std::string, std::string> properties)
@@ -90,3 +89,39 @@ compute_url(fs::path path, std::map<std::string, std::string> properties)
|
|
|
|
|
return url.string(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void server::serve_now(std::string wroot, std::string port, std::string addr) { |
|
|
|
|
|
|
|
|
|
if (spid) { |
|
|
|
|
// already serving
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int pid; |
|
|
|
|
if (!(pid = fork())) { |
|
|
|
|
|
|
|
|
|
const char *argv[] = {"stgen3", wroot.c_str(), "--port", port.c_str(),
|
|
|
|
|
"--addr", addr.c_str()}; |
|
|
|
|
int argc = 6; |
|
|
|
|
|
|
|
|
|
darkhttpd::darkhttpd_main(argc, argv); |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
this->spid = pid; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void server::stop_serving() { |
|
|
|
|
kill(spid, SIGTERM); |
|
|
|
|
waitpid(spid, NULL, 0); |
|
|
|
|
spid = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
server::~server() { |
|
|
|
|
if (spid) { |
|
|
|
|
stop_serving(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|