Correctly close a c++ server side Application

chanfrchanfr Francisco RivasOrganization: URJCProject: URJCMember
Hi all,
first of all congratulation for your awesome platform and you the support and help you give by this forum.

I have a server-side component based on Ice and I want to close correctly the application. This is an terminal based application and the way I use to kill the app is by ctrl+c.

I try some different appoaches:
1. Capturing the crtl+c event out of ICE and send a ic->shutdown to my server but I think that is not the best way.
2. Using Ice::Application the problem is that Ice:Application does not handle the crtl+c

class MyApplication : virtual public Ice::Application {
public:
    virtual int run(int, char*[]) {

        // .......
        Ice::ObjectPtr object = new MyServer::MyServerI(objPrefix, communicator());
        adapter->add(object, communicator()->stringToIdentity(name));

        adapter->activate();
        communicator()->waitForShutdown();


        //things to do before my app returns

        return 0;
    }
};

int
main(int argc, char* argv[])
{
    MyApplication app;
    return app.main(argc, argv);
}


If I run the component it creates the interfaces and everything works fine, but if I press crtl+c the applications return inmedialy not reaching the label "things to do before my app returns" and also not executing the destructor of MyServer::MyServerI


What am I doing wrong?


thanks in advance.

Comments

  • benoitbenoit Rennes, FranceBenoit FoucherOrganization: ZeroC, Inc.Project: IceAdministrators, ZeroC Staff ZeroC Staff
    Hi,

    On which platform do you get this problem? Your code looks correct. Can you try to see if you get the same issue with hello server? You can start the hello server with --Ice.Trace.Network=1, when hitting Ctrl-C you should see that the server cleanly shuts down the communicator.

    Cheers,
    Benoit.
  • chanfrchanfr Francisco RivasOrganization: URJCProject: URJCMember
    Thanks for you reply.

    I've checked with the demo and I works fine.. I don't know where is the problem. I have an IceUtil::Thread and I thought that could be the problem but I commented the thread and It still fails at application closing.

    I will check my application and post the problem it finally I find it.
Sign In or Register to comment.