Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid port is not logged in async startup #952

Open
fliiiix opened this issue Nov 26, 2024 · 0 comments
Open

Invalid port is not logged in async startup #952

fliiiix opened this issue Nov 26, 2024 · 0 comments
Labels
feature Code based project improvement

Comments

@fliiiix
Copy link
Contributor

fliiiix commented Nov 26, 2024

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

@gittiver gittiver added the feature Code based project improvement label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Code based project improvement
Projects
None yet
Development

No branches or pull requests

2 participants