set sock opts
Some checks are pending
BlockStorage/repertory/pipeline/head Build queued...

This commit is contained in:
Scott E. Graves 2025-03-25 19:11:28 -05:00
parent dce558f7b4
commit cdfa69d09f
3 changed files with 17 additions and 9 deletions

View File

@ -144,13 +144,17 @@ void server::start() {
initialize(*server_);
server_thread_ = std::make_unique<std::thread>([this]() {
#ifdef _WIN32
server_->set_socket_options([](auto &&sock) {
int enable = 1;
#if defined(_WIN32)
int enable{1};
setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
reinterpret_cast<const char *>(&enable), sizeof(enable));
#else // !defined(_WIN32)
linger opt{1, 0};
setsockopt(sock, SOL_SOCKET, SO_LINGER,
reinterpret_cast<const char *>(&opt), sizeof(opt));
#endif // defined(_WIN32)
});
#endif // _WIN32
server_->listen("127.0.0.1", config_.get_api_port());
});

View File

@ -109,13 +109,17 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
server_(server) {
REPERTORY_USES_FUNCTION_NAME();
#ifdef _WIN32
server_->set_socket_options([](auto &&sock) {
int enable = 1;
#if defined(_WIN32)
int enable{1};
setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
reinterpret_cast<const char *>(&enable), sizeof(enable));
#else // !defined(_WIN32)
linger opt{1, 0};
setsockopt(sock, SOL_SOCKET, SO_LINGER,
reinterpret_cast<const char *>(&opt), sizeof(opt));
#endif // defined(_WIN32)
});
#endif // _WIN32
server_->set_pre_routing_handler(
[this](const httplib::Request &req,

View File

@ -25,8 +25,8 @@
#include "utils/string.hpp"
namespace repertory::utils {
auto compare_version_strings(std::string version1,
std::string version2) -> std::int32_t {
auto compare_version_strings(std::string version1, std::string version2)
-> std::int32_t {
if (utils::string::contains(version1, "-")) {
version1 = utils::string::split(version1, '-', true)[0U];
@ -157,7 +157,7 @@ auto get_next_available_port(std::uint16_t first_port,
++check_port;
continue;
}
acceptor.set_option(boost::asio::ip::tcp::acceptor::linger(true, 0));
acceptor.bind({tcp::v4(), static_cast<std::uint16_t>(check_port)},
error_code);
if (error_code) {