исправления для защиты запуска вебки с некорректными аргументами командной строки

This commit is contained in:
2025-04-02 13:36:54 +03:00
parent 51431210f0
commit a6a4391123
3 changed files with 31 additions and 13 deletions

View File

@@ -23,7 +23,7 @@ namespace http::server {
connections_.clear();
}
Server::Server(const std::string &address, const std::string &port)
Server::Server(const std::string &address, int port)
: io_context_(1), signals_(io_context_), acceptor_(io_context_) {
// Register to handle the signals that indicate when the server should exit.
// It is safe to register for the same signal multiple times in a program,
@@ -39,7 +39,7 @@ namespace http::server {
// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
boost::asio::ip::tcp::resolver resolver(io_context_);
boost::asio::ip::tcp::endpoint endpoint =
*resolver.resolve(address, port).begin();
*resolver.resolve(address, std::to_string(port)).begin();
acceptor_.open(endpoint.protocol());
acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
acceptor_.bind(endpoint);
@@ -48,7 +48,7 @@ namespace http::server {
doAccept();
}
Server::Server(const std::string &address, const std::string &port, std::shared_ptr<boost::asio::ssl::context> ctx):
Server::Server(const std::string &address, int port, std::shared_ptr<boost::asio::ssl::context> ctx):
ssl_ctx(std::move(ctx)), io_context_(1), signals_(io_context_), acceptor_(io_context_) {
// Register to handle the signals that indicate when the server should exit.
// It is safe to register for the same signal multiple times in a program,
@@ -63,7 +63,7 @@ namespace http::server {
// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
boost::asio::ip::tcp::resolver resolver(io_context_);
boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(address, port).begin();
boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(address, std::to_string(port)).begin();
acceptor_.open(endpoint.protocol());
acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
acceptor_.bind(endpoint);

View File

@@ -44,8 +44,8 @@ namespace http::server {
Server &operator=(const Server &) = delete;
/// Construct the server to listen on the specified TCP address and port
explicit Server(const std::string &address, const std::string &port);
explicit Server(const std::string &address, const std::string &port, std::shared_ptr<boost::asio::ssl::context> ctx);
explicit Server(const std::string &address, int port);
explicit Server(const std::string &address, int port, std::shared_ptr<boost::asio::ssl::context> ctx);
std::vector<std::unique_ptr<resource::BasicResource>> resources;