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

Merged
merged 4 commits into from
Jan 27, 2025
Merged

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.
    int signal = ctrlCHandler.wait();
    cout << "Caught signal " << signal << ", exiting..." << 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.

Copy link
Member

@InsertCreativityHere InsertCreativityHere left a comment

Choose a reason for hiding this comment

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

I agree with @externl that it would be more ergonomic.
But I also don't think it's critical to do.

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.

Looks good!

@bernardnormier bernardnormier merged commit 7c24e53 into zeroc-ice:main Jan 27, 2025
23 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.

4 participants