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

Add wait(CtrlCHandler&) #3429

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

bernardnormier
Copy link
Member

@bernardnormier bernardnormier commented Jan 26, 2025

This PR adds a new Ice::wait(CtrlcHandler&) function and updates the doc-comments for CtrlCHandler.

With this new wait function, a typical C++ server is as follows - we don't need communicator->waitForShutdown:

int
main(int argc, char* argv[])
{
    // CtrlCHandler handles Ctrl+C and similar signals. It must be created at the beginning of the program, before
    // starting any thread.
    Ice::CtrlCHandler ctrlCHandler;

    const Ice::CommunicatorHolder communicatorHolder{argc, argv};
    const Ice::CommunicatorPtr& communicator = communicatorHolder.communicator();

    auto adapter = communicator->createObjectAdapterWithEndpoints("GreeterAdapter", "tcp -p 4061");
    adapter->add(make_shared<GreeterServer::Chatbot>(), Ice::stringToIdentity("greeter"));
    adapter->activate();

    // Wait until the user presses Ctrl+C.
    wait(ctrlCHandler);
    cout << "done" << endl;

    return 0;
}

Copy link
Member

@externl externl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have wait be a member function on CtrlCHandler, like std::condition_variable's wait().

I'm not sure I see the benefit of having a non-member function in this case as there's no abstraction of any kind.

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.

3 participants