http server functional
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -16,3 +16,6 @@
|
|||||||
[submodule "external/BLAKE3"]
|
[submodule "external/BLAKE3"]
|
||||||
path = external/BLAKE3
|
path = external/BLAKE3
|
||||||
url = https://github.com/BLAKE3-team/BLAKE3
|
url = https://github.com/BLAKE3-team/BLAKE3
|
||||||
|
[submodule "external/cpp-httplib"]
|
||||||
|
path = external/cpp-httplib
|
||||||
|
url = https://github.com/yhirose/cpp-httplib
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ add_subdirectory(external/tomlplusplus)
|
|||||||
add_subdirectory(external/duckdb)
|
add_subdirectory(external/duckdb)
|
||||||
add_subdirectory(external/json)
|
add_subdirectory(external/json)
|
||||||
add_subdirectory(external/BLAKE3/c)
|
add_subdirectory(external/BLAKE3/c)
|
||||||
|
add_subdirectory(external/cpp-httplib)
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
# Executables
|
# Executables
|
||||||
@@ -40,6 +41,7 @@ set(COMMON_LIBS
|
|||||||
duckdb_static
|
duckdb_static
|
||||||
nlohmann_json
|
nlohmann_json
|
||||||
blake3
|
blake3
|
||||||
|
# cpp-httplib
|
||||||
)
|
)
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
@@ -52,6 +54,7 @@ set(EXTERNAL_INCLUDES
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/external/duckdb/src/include
|
${CMAKE_CURRENT_SOURCE_DIR}/external/duckdb/src/include
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/external/json/include/nlohmann
|
${CMAKE_CURRENT_SOURCE_DIR}/external/json/include/nlohmann
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/external/BLAKE3/c
|
${CMAKE_CURRENT_SOURCE_DIR}/external/BLAKE3/c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/external/cpp-httplib
|
||||||
)
|
)
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
[hostname]
|
[hostname]
|
||||||
base_path="https://tracker.example.com"
|
base_path="https://tracker.example.com"
|
||||||
inter_comm_port=8032
|
inter_comm_port=8032
|
||||||
|
http_port=9032
|
||||||
|
|||||||
1
external/cpp-httplib
vendored
Submodule
1
external/cpp-httplib
vendored
Submodule
Submodule external/cpp-httplib added at db561f5552
@@ -11,6 +11,8 @@
|
|||||||
#include "../shared-utils/socket-utils.hpp"
|
#include "../shared-utils/socket-utils.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <httplib.h>
|
||||||
|
|
||||||
namespace socket_manager {
|
namespace socket_manager {
|
||||||
void start_daemon(std::uint16_t port){
|
void start_daemon(std::uint16_t port){
|
||||||
int server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
int server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
@@ -45,4 +47,12 @@ void handle_client(int client_socket){
|
|||||||
close(client_socket);
|
close(client_socket);
|
||||||
spdlog::debug("Connection closed gracefully {}", client_socket);
|
spdlog::debug("Connection closed gracefully {}", client_socket);
|
||||||
}
|
}
|
||||||
|
void start_http_server(std::uint16_t port){
|
||||||
|
spdlog::info("Starting HTTP server on {}", port);
|
||||||
|
httplib::Server server = httplib::Server{};
|
||||||
|
server.Get("/test", [](const httplib::Request &, httplib::Response &res) {
|
||||||
|
res.set_content("Hello World!", "text/plain");
|
||||||
|
});
|
||||||
|
server.listen("0.0.0.0", port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,6 @@
|
|||||||
namespace socket_manager {
|
namespace socket_manager {
|
||||||
void handle_client(int client_socket);
|
void handle_client(int client_socket);
|
||||||
void start_daemon(std::uint16_t port);
|
void start_daemon(std::uint16_t port);
|
||||||
|
void start_http_server(std::uint16_t port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,17 @@ int main() {
|
|||||||
auto config = toml::parse_file("host-config.toml");
|
auto config = toml::parse_file("host-config.toml");
|
||||||
std::string http_server_fqdn = config["hostname"]["base_path"].value_or("http://example.com");
|
std::string http_server_fqdn = config["hostname"]["base_path"].value_or("http://example.com");
|
||||||
std::uint16_t inter_comm_port = config["hostname"]["inter_comm_port"].value_or(8033);
|
std::uint16_t inter_comm_port = config["hostname"]["inter_comm_port"].value_or(8033);
|
||||||
|
std::uint16_t http_port = config["hostname"]["http_port"].value_or(9033);
|
||||||
|
|
||||||
spdlog::debug("Path collected: {}", http_server_fqdn);
|
spdlog::debug("Path collected: {}", http_server_fqdn);
|
||||||
spdlog::debug("Port collected for inter-process communication {}", inter_comm_port);
|
spdlog::debug("Port collected for inter-process communication {}", inter_comm_port);
|
||||||
|
|
||||||
std::thread socket_management_root = std::thread{socket_manager::start_daemon, inter_comm_port};
|
std::thread socket_management_root = std::thread{socket_manager::start_daemon, inter_comm_port};
|
||||||
|
socket_management_root.detach();
|
||||||
spdlog::info("socket management thread started and detached");
|
spdlog::info("socket management thread started and detached");
|
||||||
|
std::thread http_server_root = std::thread{socket_manager::start_http_server, http_port};
|
||||||
|
http_server_root.detach();
|
||||||
|
spdlog::info("http root thread has been started and detached.");
|
||||||
while (true) {
|
while (true) {
|
||||||
sleep(100);
|
sleep(100);
|
||||||
spdlog::debug("Status of socket management thread: {}", socket_management_root.joinable());
|
spdlog::debug("Status of socket management thread: {}", socket_management_root.joinable());
|
||||||
|
|||||||
Reference in New Issue
Block a user