established buffer, must now switch to json
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
[hostname]
|
||||
base_path="https://tracker.example.com"
|
||||
inter_comm_port=8032
|
||||
|
||||
25
src/daemon-utils/socket-manager.cpp
Normal file
25
src/daemon-utils/socket-manager.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "socket-manager.hpp"
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <thread>
|
||||
|
||||
void start_daemon(std::uint16_t port){
|
||||
int server_socket = socket(AF_INET, SOCK_STREAM, 0);
|
||||
sockaddr_in server_address;
|
||||
server_address.sin_family = AF_INET;
|
||||
server_address.sin_port = htons(8080);
|
||||
server_address.sin_addr.s_addr = INADDR_ANY;
|
||||
bind(server_socket, (struct sockaddr*)&server_address,
|
||||
sizeof(server_address));
|
||||
|
||||
// listening to the assigned socket
|
||||
listen(server_socket, 5);
|
||||
while(true){
|
||||
int client_socket = accept(server_socket, nullptr,nullptr);
|
||||
std::thread client_handling_thread = std::thread{handle_client, client_socket};
|
||||
}
|
||||
}
|
||||
|
||||
void handle_client(int client_socket){
|
||||
|
||||
}
|
||||
6
src/daemon-utils/socket-manager.hpp
Normal file
6
src/daemon-utils/socket-manager.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <sys/socket.h>
|
||||
#include <cstdint>
|
||||
#include <netinet/in.h>
|
||||
void handle_client(int client_socket);
|
||||
void start_daemon(std::uint16_t port);
|
||||
@@ -1,4 +1,7 @@
|
||||
#include "spdlog/common.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <toml++/toml.hpp>
|
||||
// This is the *daemon*
|
||||
@@ -6,9 +9,18 @@
|
||||
int main() {
|
||||
std::cout << "Hello from the email tracker's daemon (C++23)\n";
|
||||
spdlog::info("Logger is functional.");
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
|
||||
bool does_exist_config = std::filesystem::exists("host-config.toml");
|
||||
spdlog::debug("Host config existential status: {}", does_exist_config);
|
||||
if (!does_exist_config) return -1;
|
||||
|
||||
auto config = toml::parse_file("host-config.toml");
|
||||
|
||||
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);
|
||||
|
||||
spdlog::debug("Path collected: {}", http_server_fqdn);
|
||||
spdlog::debug("Port collected for inter-process communication {}", inter_comm_port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
namespace serializable {
|
||||
template <typename S>
|
||||
void serialize(S &s, HandshakeConnection &object){
|
||||
s.value2b(object.payload);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <bitsery/bitsery.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace serializable{
|
||||
|
||||
Reference in New Issue
Block a user