ready to write the database commands
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include <httplib.h>
|
||||
|
||||
namespace socket_manager {
|
||||
void start_daemon(std::uint16_t port){
|
||||
void start_daemon(std::uint16_t port, std::shared_ptr<duckdb::Connection> connection ){
|
||||
int server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
sockaddr_in server_address;
|
||||
server_address.sin_family = AF_INET;
|
||||
@@ -28,13 +28,13 @@ namespace socket_manager {
|
||||
while(true){
|
||||
int client_socket = accept(server_socket, nullptr,nullptr);
|
||||
spdlog::info("new socket created");
|
||||
std::thread client_handling_thread = std::thread{handle_client, client_socket};
|
||||
std::thread client_handling_thread = std::thread{handle_client, client_socket, connection};
|
||||
client_handling_thread.detach();
|
||||
spdlog::debug("new thread spun up, returning to main loop");
|
||||
}
|
||||
}
|
||||
|
||||
void handle_client(int client_socket){
|
||||
void handle_client(int client_socket, std::shared_ptr<duckdb::Connection> connection ){
|
||||
std::vector buffer = std::vector<char>{};
|
||||
serializable::HandshakeConnection prelim_handshake = serializable::HandshakeConnection{.payload = 123};
|
||||
nlohmann::json to_dump_handshake = prelim_handshake;
|
||||
@@ -47,7 +47,7 @@ void handle_client(int client_socket){
|
||||
close(client_socket);
|
||||
spdlog::debug("Connection closed gracefully {}", client_socket);
|
||||
}
|
||||
void start_http_server(std::uint16_t port){
|
||||
void start_http_server(std::uint16_t port, std::shared_ptr<duckdb::Connection> connection ){
|
||||
spdlog::info("Starting HTTP server on {}", port);
|
||||
httplib::Server server = httplib::Server{};
|
||||
std::vector<char> pixel = other_general_utils::read_file_bytes("1x1.png");
|
||||
@@ -82,3 +82,9 @@ void start_http_server(std::uint16_t port){
|
||||
server.listen("0.0.0.0", port);
|
||||
}
|
||||
}
|
||||
|
||||
namespace database_utils {
|
||||
void initialize_db(std::shared_ptr<duckdb::Connection> connection){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
#include <sys/socket.h>
|
||||
#include <cstdint>
|
||||
#include <netinet/in.h>
|
||||
#include <duckdb.hpp>
|
||||
|
||||
namespace socket_manager {
|
||||
void handle_client(int client_socket);
|
||||
void start_daemon(std::uint16_t port);
|
||||
void start_http_server(std::uint16_t port);
|
||||
void handle_client(int client_socket, std::shared_ptr<duckdb::Connection> connection );
|
||||
void start_daemon(std::uint16_t port, std::shared_ptr<duckdb::Connection> connection );
|
||||
void start_http_server(std::uint16_t port, std::shared_ptr<duckdb::Connection> connection );
|
||||
}
|
||||
|
||||
namespace database_utils {
|
||||
void initialize_db(std::shared_ptr<duckdb::Connection> connection);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
#include "duckdb/main/connection.hpp"
|
||||
#include "duckdb/main/database.hpp"
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <toml++/toml.hpp>
|
||||
#include <unistd.h>
|
||||
#include "daemon-utils/socket-manager.hpp"
|
||||
#include <duckdb.hpp>
|
||||
// This is the *daemon*
|
||||
|
||||
int main() {
|
||||
@@ -25,10 +29,13 @@ int main() {
|
||||
spdlog::debug("Path collected: {}", http_server_fqdn);
|
||||
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};
|
||||
duckdb::DuckDB duck_in_memory_database = duckdb::DuckDB{nullptr};
|
||||
std::shared_ptr<duckdb::Connection> connection = std::make_shared<duckdb::Connection>(duck_in_memory_database);
|
||||
|
||||
std::thread socket_management_root = std::thread{socket_manager::start_daemon, inter_comm_port, connection};
|
||||
socket_management_root.detach();
|
||||
spdlog::info("socket management thread started and detached");
|
||||
std::thread http_server_root = std::thread{socket_manager::start_http_server, http_port};
|
||||
std::thread http_server_root = std::thread{socket_manager::start_http_server, http_port, connection};
|
||||
http_server_root.detach();
|
||||
spdlog::info("http root thread has been started and detached.");
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user