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

Resolve #2017 #2022

Merged
merged 3 commits into from
Jan 17, 2025
Merged

Resolve #2017 #2022

merged 3 commits into from
Jan 17, 2025

Conversation

yhirose
Copy link
Owner

@yhirose yhirose commented Jan 17, 2025

No description provided.

@ngxson
Copy link

ngxson commented Jan 17, 2025

This is great, thanks a lot for the rapid response!

I implemented it this PR and it just works.

Do you think it's better to add an example in README? I'd suggest this:

// If the handler takes time to finish, you can also poll the connection state

svr.Get("/task", [&](const Request& req, Response& res) {
  const char * result = nullptr;
  process.run(); // for example, starting an external process
  while (result == nullptr) {
    sleep(1);
    if (req.is_connection_closed()) {
      process.kill(); // kill the process
      return;
    }
    result = process.stdout(); // != nullptr if the process finishes
  }
  res.set_content(result, "text/plain");
});

Btw, not related to this, but I got this warning when compiling the file:

httplib.h:2576:2: warning: extra ';' outside of a function is incompatible with C++98 [-Wc++98-compat-extra-semi]

Would you mind to also remove this semicolon, so it can be compiled with -Werror? Thanks again.

@yhirose
Copy link
Owner Author

yhirose commented Jan 17, 2025

@ngxson I have updated the code and README according to your suggestions. Thanks for your fine contribution!

@yhirose yhirose merged commit 986a20f into master Jan 17, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants