GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Feature Request: Add callback for successful server start event · Issue #2467 · yhirose/cpp-httplib

Feature Request: Add callback for successful server start event #2467

New issue
Copy link
New issue
Copy link
Closed
Closed
Feature Request: Add callback for successful server start event#2467
Copy link

Description

@kobe2000
kobe2000
opened on Jun 4, 2026
Issue body actions

Is your feature request related to a problem? Please describe.

Currently, when using httplib::Server::listen(), there's no direct callback to notify when the server has successfully started and is ready to accept connections. The listen() method blocks until the server stops, and while it returns true upon successful start, the success confirmation happens right at the beginning of the blocking call.

This makes it inconvenient when:

  • Running the server in a background thread and needing to know exactly when it's ready
  • Implementing health checks or startup probes
  • Logging server start events with precise timing
  • Coordinating multiple services that depend on this server being ready

Describe the solution you'd like

I propose adding a callback mechanism similar to the existing set_*_handler pattern. For example:

// Option 1: A simple setter
svr.set_start_handler([]() {
    std::cout << "Server successfully started on port 8080" << std::endl;
});

// Option 2: Pass callback as parameter to listen()
svr.listen("0.0.0.0", 8080, []() {
    std::cout << "Server is now ready" << std::endl;
});

The callback should be invoked immediately after the socket binds successfully and the server begins accepting connections (or is ready to do so).

Describe alternatives you've considered

Currently, the best workarounds are:

  1. Using wait_until_ready() - This works well for threaded scenarios:
std::thread t([&]() { svr.listen("0.0.0.0", 8080); });
svr.wait_until_ready();
std::cout << "Server ready" << std::endl;
  1. Checking listen() return value - But this requires careful thread synchronization since listen() blocks immediately:
if (svr.listen("0.0.0.0", 8080)) {
    // This runs immediately, but before any actual serving happens?
    std::cout << "Server started" << std::endl;
}

However, these approaches require extra synchronization logic or rely on behavior that isn't explicitly documented for this purpose. A dedicated callback would be cleaner and more intuitive.

Additional context

This feature exists in many other HTTP server libraries (e.g., Node.js server.listen(callback), Python's HTTPServer with custom serve_forever). Adding this would improve the library's usability, especially for users who need deterministic startup notifications.

Thank you for maintaining this excellent library!

Activity

  1. yhirose
    closed this as completedin 0c2f535on Jun 5, 2026
  2. apocelipes
    added a commit that references this issue on Jun 5, 2026

    Fix yhirose#2467

    This issue will close once commit 0c2f535 is merged into the 'master' branch.
    0c2f535
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.