prevent overlapping api ports
This commit is contained in:
parent
c2eaa92f4a
commit
e53acf799a
@ -143,8 +143,11 @@ void server::start() {
|
|||||||
|
|
||||||
initialize(*server_);
|
initialize(*server_);
|
||||||
|
|
||||||
server_thread_ = std::make_unique<std::thread>(
|
fmt::println("port|{}", config_.get_api_port());
|
||||||
[this]() { server_->listen("127.0.0.1", config_.get_api_port()); });
|
server_thread_ = std::make_unique<std::thread>([this]() {
|
||||||
|
server_->set_socket_options([](auto && /* sock */) {});
|
||||||
|
server_->listen("127.0.0.1", config_.get_api_port());
|
||||||
|
});
|
||||||
event_system::instance().raise<service_start_end>(function_name, "server");
|
event_system::instance().raise<service_start_end>(function_name, "server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ mount(std::vector<const char *> args, std::string data_directory,
|
|||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
lock_data global_lock(provider_type::unknown, "global");
|
lock_data global_lock(provider_type::unknown, "global");
|
||||||
lock_result = global_lock.grab_lock();
|
lock_result = global_lock.grab_lock(100U);
|
||||||
if (lock_result != lock_result::success) {
|
if (lock_result != lock_result::success) {
|
||||||
std::cerr << "FATAL: Unable to get global lock" << std::endl;
|
std::cerr << "FATAL: Unable to get global lock" << std::endl;
|
||||||
return exit_code::lock_failed;
|
return exit_code::lock_failed;
|
||||||
@ -112,6 +112,7 @@ mount(std::vector<const char *> args, std::string data_directory,
|
|||||||
std::cerr << "FATAL: Unable to get available port" << std::endl;
|
std::cerr << "FATAL: Unable to get available port" << std::endl;
|
||||||
return exit_code::startup_exception;
|
return exit_code::startup_exception;
|
||||||
}
|
}
|
||||||
|
fmt::println("port|{}", port);
|
||||||
config.set_api_port(port);
|
config.set_api_port(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +169,7 @@ mount(std::vector<const char *> args, std::string data_directory,
|
|||||||
std::cerr << "failed to set mount state" << std::endl;
|
std::cerr << "failed to set mount state" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global_lock.release();
|
||||||
mount_result = drive.mount(drive_args);
|
mount_result = drive.mount(drive_args);
|
||||||
return exit_code::mount_result;
|
return exit_code::mount_result;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
@ -188,6 +190,8 @@ mount(std::vector<const char *> args, std::string data_directory,
|
|||||||
if (not lock.set_mount_state(true, "", -1)) {
|
if (not lock.set_mount_state(true, "", -1)) {
|
||||||
std::cerr << "failed to set mount state" << std::endl;
|
std::cerr << "failed to set mount state" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global_lock.release();
|
||||||
mount_result = drive.mount(drive_args);
|
mount_result = drive.mount(drive_args);
|
||||||
return exit_code::mount_result;
|
return exit_code::mount_result;
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
|
@ -109,6 +109,8 @@ handlers::handlers(mgmt_app_config *config, httplib::Server *server)
|
|||||||
server_(server) {
|
server_(server) {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
|
server->set_socket_options([](auto && /* sock */) {});
|
||||||
|
|
||||||
server_->set_pre_routing_handler(
|
server_->set_pre_routing_handler(
|
||||||
[this](const httplib::Request &req,
|
[this](const httplib::Request &req,
|
||||||
auto &&res) -> httplib::Server::HandlerResponse {
|
auto &&res) -> httplib::Server::HandlerResponse {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user