Skip to content

Invalid port is not logged in async startup #952

@fliiiix

Description

@fliiiix

New feature to log that the port is already used instead of just timeouting.

Consider the following example:

#include "crow_all.h"

int main(int /*ac*/, char ** /*av*/) {
  CROW_LOG_INFO << "Playing some music";

  crow::SimpleApp app;

  CROW_ROUTE(app, "/")
  ([]() { return "Hello World";  });

  app.loglevel(crow::LogLevel::DEBUG);
  app.bindaddr("0.0.0.0").port(8000).multithreaded().run_async();

  CROW_LOG_INFO << "Before wait";
  auto status = app.wait_for_server_start();
  CROW_LOG_INFO << "After wait";

  if (status == std::cv_status::timeout)
  {
    CROW_LOG_INFO << "Timeout";
  }
}

Which logs this if the port is already used (or nothing without custom logs)

(2024-11-26 12:01:46) [INFO    ] Playing some music
(2024-11-26 12:01:46) [INFO    ] Before wait
(2024-11-26 12:01:49) [INFO    ] After wait
(2024-11-26 12:01:49) [INFO    ] Timeout

Vs the error you get with run()

(2024-11-26 12:01:11) [INFO    ] Playing some music
terminate called after throwing an instance of 'std::system_error'
  what():  bind: Address already in use
[1]    1518945 IOT instruction  ./src/radiopi

The address is already validated with: #918 logging

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureCode based project improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions