Allow listening on multiple interfaces

This commit is contained in:
2025-09-03 16:09:16 -04:00
parent b8eb00e313
commit 46edb7cd26
6 changed files with 172 additions and 106 deletions

View File

@@ -3,19 +3,40 @@
#include <chrono>
#include <optional>
#include <string>
#include <vector>
namespace weaseldb {
/**
* @brief Configuration for a single network interface to listen on.
*/
struct ListenInterface {
enum class Type { TCP, Unix };
Type type;
/// For TCP: IP address to bind to (e.g., "127.0.0.1", "0.0.0.0")
std::string address;
/// For TCP: port number
int port = 0;
/// For Unix: socket file path
std::string path;
// Factory methods for cleaner config creation
static ListenInterface tcp(const std::string &addr, int port_num) {
return {Type::TCP, addr, port_num, ""};
}
static ListenInterface unix_socket(const std::string &socket_path) {
return {Type::Unix, "", 0, socket_path};
}
};
/**
* @brief Configuration settings for the WeaselDB server component.
*/
struct ServerConfig {
/// IP address to bind the server to (default: localhost)
std::string bind_address = "127.0.0.1";
/// TCP port number for the server to listen on
int port = 8080;
/// Unix socket path (if specified, takes precedence over TCP)
std::string unix_socket_path;
/// Network interfaces to listen on (TCP and/or Unix sockets)
std::vector<ListenInterface> interfaces;
/// Maximum size in bytes for incoming HTTP requests (default: 1MB)
int64_t max_request_size_bytes = 1024 * 1024;
/// Number of I/O threads for handling connections and network events